The dev environment is based on HardHat, along with other tools commonly used with Hardhat in the ecosystem.
Pull the repo and run
npm install
npx hardhat test
We use hardhat-deploy plugin to deploy easily. Ensure that MNEMONiC
is set in .env
file before deploying.
npx hardhat deploy --network celo --tags OnChainEscrow --write true
We have deployed the contract OnChainEscrow
on Celo forno. Here’s the link to Celo explorer. You can see there are some test transactions already.
There are four scripts under the scripts
directory, each showing an example of different situations for on-chain escrow contract.
- Successful trade between seller and buyer
- Buyer cancels after the seller has funded the escrow
- Dispute won by the seller
- Dispute won by the buyer
Before running the example script, please ensure the .env
file has all four env variables populated correctly. Then fund the seller and relayer wallets with a small amount of CELO, say 1 CELO each. The trade value is 0.01 CELO. So anything more than that should do ideally.
If you deploy the contract again, please change the contract address in the script too. Current address is 0xE4789582d80935353d0aF9f46e07e61649c97339
.
npx hardhat run scripts/HappyCeloGoldTrade.ts
- We fetch the deployed contract
- Approve the contract address via seller to spend funds on seller’s behalf
- Prepare the escrow transaction and broadcast
- The contract stores all the current trades in memory, we cross-check that
- Finally, we release the escrowed funds to the buyer and this time through the relayer
The rest of the three situations follow similar patterns, but of course different execution paths.
There’s one additional script to demonstrate a cUSD trade as well, HappyCeloDollarTrade.ts