|
| 1 | +# World ID On-Chain Template |
| 2 | + |
| 3 | +Template repository for a World ID On-Chain Integration. |
| 4 | + |
| 5 | +## Local Development |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +Create a staging on-chain app in the [Worldcoin Developer Portal](https://developer.worldcoin.org). |
| 10 | + |
| 11 | +Ensure you have installed [Foundry](https://book.getfoundry.sh/getting-started/installation), [NodeJS](https://nodejs.org/en/download), and [pnpm](https://pnpm.io/installation). |
| 12 | + |
| 13 | +### Local Testnet Setup |
| 14 | + |
| 15 | +Start a local node forked from Optimism Sepolia, replacing `$YOUR_API_KEY` with your Alchemy API key: |
| 16 | + |
| 17 | +```bash |
| 18 | +# leave this running in the background |
| 19 | +anvil -f https://opt-sepolia.g.alchemy.com/v2/$YOUR_API_KEY |
| 20 | +``` |
| 21 | + |
| 22 | +In another shell, deploy the contract, replacing `$WORLD_ID_ROUTER` with the [World ID Router address](https://docs.worldcoin.org/reference/address-book) for your selected chain, `$NEXT_PUBLIC_APP_ID` with the app ID as configured in the [Worldcoin Developer Portal](https://developer.worldcoin.org), and `$NEXT_PUBLIC_ACTION` with the action ID as configured in the Worldcoin Developer Portal: |
| 23 | + |
| 24 | +```bash |
| 25 | +cd contracts |
| 26 | +forge create --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 src/Contract.sol:Contract --constructor-args $WORLD_ID_ROUTER $NEXT_PUBLIC_APP_ID $NEXT_PUBLIC_ACTION |
| 27 | +``` |
| 28 | + |
| 29 | +Note the `Deployed to:` address from the output. |
| 30 | + |
| 31 | +### Local Web Setup |
| 32 | + |
| 33 | +In a new shell, install project dependencies: |
| 34 | + |
| 35 | +```bash |
| 36 | +pnpm i |
| 37 | +``` |
| 38 | + |
| 39 | +Set up your environment variables in the `.env` file. You will need to set the following variables: |
| 40 | +- `NEXT_PUBLIC_APP_ID`: The app ID as configured in the [Worldcoin Developer Portal](https://developer.worldcoin.org). |
| 41 | +- `NEXT_PUBLIC_ACTION`: The action ID as configured in the Worldcoin Developer Portal. |
| 42 | +- `NEXT_PUBLIC_WALLETCONNECT_ID`: Your WalletConnect ID. |
| 43 | +- `NEXT_PUBLIC_CONTRACT_ADDRESS`: The address of the contract deployed in the previous step. |
| 44 | + |
| 45 | +Start the development server: |
| 46 | + |
| 47 | +```bash |
| 48 | +pnpm dev |
| 49 | +``` |
| 50 | + |
| 51 | +The Contract ABI will be automatically re-generated and saved to `src/abi/ContractAbi.json` on each run of `pnpm dev`. |
| 52 | + |
| 53 | +### Iterating |
| 54 | + |
| 55 | +After making changes to the contract, you should: |
| 56 | +- re-run the `forge create` command from above |
| 57 | +- replace the `NEXT_PUBLIC_CONTRACT_ADDRESS` environment variable with the new contract address |
| 58 | +- if your contract ABI has changed, restart the local web server |
| 59 | + |
| 60 | +### Testing |
| 61 | + |
| 62 | +You'll need to import the private keys on the local testnet into your wallet used for local development. The default development seed phrase is `test test test test test test test test test test test junk`. |
| 63 | + |
| 64 | +> [!CAUTION] |
| 65 | +> This is only for local development. Do not use this seed phrase on mainnet or any public testnet. |
| 66 | +
|
| 67 | +When connecting your wallet to the local development environment, you will be prompted to add the network to your wallet. |
| 68 | + |
| 69 | +Use the [Worldcoin Simulator](https://simulator.worldcoin.org) in place of World App to scan the IDKit QR codes and generate the zero-knowledge proofs. |
0 commit comments