Skip to content

Commit

Permalink
fix(cli-template-contracts-foundry): fix yarn dev command and add d…
Browse files Browse the repository at this point in the history
…ocs on integrate w/ boilerplate
  • Loading branch information
jimmychu0807 committed Dec 3, 2024
1 parent d96a611 commit 8075e11
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/cli-template-contracts-foundry/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Foundry artifact
cache/
out/

# artifact for deploying on local Anvil node
**/31337
46 changes: 46 additions & 0 deletions packages/cli-template-contracts-foundry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,49 @@ Or to automatically format the code:
```bash
yarn prettier:write
```

### Integrating with Semaphore Boilerplate

You can also integrate this project with [Semaphore Boilerplate](https://github.com/semaphore-protocol/boilerplate), using this project as the contract end and connecting with Boilerplate front end.

1. In `cli-template-contracts-foundry` package directory, run:

```sh
yarn install
yarn dev
```

After running `yarn dev`, notice the output of

```sh
# ...
# ...
== Return ==
feedbackAddr: address 0x6f1AFCA8BCA87bF02091AF6187a5002802f9FB31
semaphoreAddr: address 0xb730ce6CAE3FB706e83E4E00dFA31623966570eB
semaphoreVerifierAddr: address 0xE2c114f548bEf410eaCe04D0390b61cc963df295
# ...
# ...
```

2. Now, with another terminal, clone Semaphore Boilerplate down:

```sh
# Clone Semaphore boilerplate and build dependencies
git clone https://github.com/semaphore-protocol/boilerplate.git
cd boilerplate
yarn install
# Use the sample .env.example
cp .env.example .env
```

3. Open the file `apps/web-app/.env.development`. Modify the values of `NEXT_PUBLIC_FEEDBACK_CONTRACT_ADDRESS` and `NEXT_PUBLIC_SEMAPHORE_CONTRACT_ADDRESS` with **feedbackAddr** and **semaphoreAddr** values shown in step 1.

4. Run the Boilerplate front end:

```sh
yarn dev:web-app
```
1 change: 1 addition & 0 deletions packages/cli-template-contracts-foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libs = ["node_modules"]
allow_paths = ["*", "../.."]

[rpc_endpoints]
anvil = "http://127.0.0.1:8545"
# sepolia = "${SEPOLIA_RPC_URL}"

[etherscan]
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-template-contracts-foundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"wait-on": "^8.0.1"
},
"scripts": {
"dev": "anvil --no-mining & (wait-on tcp:8545 && LOG=true forge script script/DeployFeedback.s.sol --chain 31337 --broadcast)",
"dev": "anvil & (wait-on tcp:8545 && forge script script/DeployFeedback.s.sol --rpc-url anvil --broadcast --sender 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)",
"compile": "forge build",
"clean": "forge clean",
"test": "forge test -vvv",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,33 @@ import {Feedback} from "../src/Feedback.sol";
import {Semaphore} from "@semaphore/contracts/Semaphore.sol";
import {SemaphoreVerifier} from "@semaphore/contracts/base/SemaphoreVerifier.sol";
import {ISemaphoreVerifier} from "@semaphore/contracts/interfaces/ISemaphoreVerifier.sol";
import {console, Script} from "forge-std/Script.sol";
import {Script} from "forge-std/Script.sol";

contract DeployFeedback is Script {
function run() external returns (address feedbackAddr, address semaphoreAddr) {
address semaphoreVerifierAddr;
// Passing SALT parameter to use CREATE2 for deterministic contract address
bytes32 constant SALT = bytes32(0);

contract DeployFeedback is Script {
function run() external returns (address feedbackAddr, address semaphoreAddr, address semaphoreVerifierAddr) {
// Default to use the first test user private key of anvil node
uint256 deployerPrivateKey = vm.envOr(
"PRIVATE_KEY",
uint256(0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80)
);
bool log = vm.envOr("LOG", false);

vm.startBroadcast(deployerPrivateKey);

// Deploy SemaphoreVerifier
SemaphoreVerifier semaphoreVerifierContract = new SemaphoreVerifier();
SemaphoreVerifier semaphoreVerifierContract = new SemaphoreVerifier{salt: SALT}();
semaphoreVerifierAddr = address(semaphoreVerifierContract);

// Deploy Semaphore
Semaphore semaphoreContract = new Semaphore(ISemaphoreVerifier(semaphoreVerifierAddr));
Semaphore semaphoreContract = new Semaphore{salt: SALT}(ISemaphoreVerifier(semaphoreVerifierAddr));
semaphoreAddr = address(semaphoreContract);

// Deploy Feedback
Feedback feedbackContract = new Feedback(semaphoreAddr);
Feedback feedbackContract = new Feedback{salt: SALT}(semaphoreAddr);
feedbackAddr = address(feedbackContract);

vm.stopBroadcast();

if (log) {
/* solhint-disable no-console */
console.log("SemaphoreVerifier contract has been deployed to:", semaphoreVerifierAddr);
console.log("Semaphore contract has been deployed to:", semaphoreAddr);
console.log("Feedback contract has been deployed to:", feedbackAddr);
/* solhint-enable no-console */
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract FeedbackTest is Test {

function setUp() external {
DeployFeedback deployFeedback = new DeployFeedback();
(address feedbackAddress, address semaphoreAddress) = deployFeedback.run();
(address feedbackAddress, address semaphoreAddress, ) = deployFeedback.run();
feedbackContract = Feedback(feedbackAddress);
semaphoreContract = ISemaphore(semaphoreAddress);
semaphoreGroups = ISemaphoreGroups(semaphoreAddress);
Expand Down

0 comments on commit 8075e11

Please sign in to comment.