Deployment & Testnet Interactions

CoinFlip

Deployed CoinFlip.sol randomness consumer contract Example: https://sepolia.etherscan.io/address/0xed963038113af313c24c1650e3df67eedd469f09

Deployment & Setup

  1. Deploy contract in 1st terminal: forge script script/deploy.s.sol --rpc-url $SEPOLIA_RPC_URL --broadcast

  2. Start oracle from 2nd terminal: cd oracle -> node oracle.js. This starts the listener. (WebSocket RPC Sepolia needed).

  3. Fork sepolia from 3rd terminal: anvil --fork-url $SEPOLIA_RPC_URL.

  4. export CoinFlip contract in 1st bash terminal: export CoinFlip="0xEd963038113af313c24c1650e3Df67eeDD469F09"

Sepolia Interactions

Interactions are done in 1st terminal while you have oracle running and anvil running in 2nd and 3rd terminals. Anvil fork of Sepolia takes a snapshot of current state. Therefore, when you change state, you must close and restart the anvil fork to get the latest Sepolia block and see any updates to state that happened.

  • Get all users info anytime with cast call $CoinFlip "userInfo(address)" $ALICE

  • Get users accrued winnings with cast call $CoinFlip "userWinnings(address)" $ALICE

  1. Set users future block: cast send $CoinFlip "setUsersBlockNumber()" --from $ALICE --private-key $ALICE_PK --rpc-url $SEPOLIA_RPC_URL --value 1000000000000000

  2. Request randomness (re-run sepolia fork when block has passed): cast send $CoinFlip "requestRandomness()" --from $ALICE --private-key $ALICE_PK --rpc-url $SEPOLIA_RPC_URL

  3. Flip coin, yielding either 1 or 2: cast send $CoinFlip "useRandomness()" --from $ALICE --private-key $ALICE_PK --rpc-url $SEPOLIA_RPC_URL

  4. If contract is solvent, and you've own, you can claim winnings: cast send $CoinFlip "claimWinnings()" --from $ALICE --private-key $ALICE_PK --rpc-url $SEPOLIA_RPC_URL

CoinFlipMulti

The same as CoinFlip, except deployed here: https://sepolia.etherscan.io/address/0x2d4f5a2F4802eEE5A22A4fadC3b8ec87Bc90fB51

Also, setUsersBlockNumber() changed to setUsersBlockNumbers(). And fulfillRandomWords() function signature changed.

Last updated