|
1 | 1 | # Coin Flip Example application
|
2 | 2 |
|
3 |
| -The coin flip example demonstrates how to use Pyth Entropy to flip a fair coin. |
| 3 | +This directory contains an example application that demonstrates how to use Pyth Entropy to flip a fair coin. |
| 4 | +The example consists of a Solidity contract that implements a coin flip and a Typescript script that interacts with the contract. |
4 | 5 |
|
5 |
| -## Try it out |
6 |
| - |
7 |
| -To try the example, first run the following commands from the root of the `pyth-crosschain` repository: |
| 6 | +Please note that this example is for demonstration purposes only and should not be used in production. |
8 | 7 |
|
9 |
| -```shell |
10 |
| -npm install |
11 |
| -npx lerna run build |
12 |
| -``` |
| 8 | +Please see the Pyth Entropy [documentation](https://docs.pyth.network/entropy) for more information. |
13 | 9 |
|
14 |
| -These commands will build dependencies for the typescript project. |
| 10 | +## Try it out |
15 | 11 |
|
16 |
| -Next, choose a network to run the example on. |
| 12 | +First, you have to choose a network to run the example on. |
17 | 13 | The example has been deployed on the following networks:
|
18 | 14 |
|
19 | 15 | ```
|
20 |
| -| Chain Name | Address | RPC | |
21 |
| -|------------------|--------------------------------------------|--------------------------------------------| |
22 |
| -| optimism-sepolia | 0x2eE67fF5d8548fF544f2c178a0FcAFe503A634Be | https://sepolia.optimism.io/ | |
23 |
| -| arbitrum-sepolia | 0xCd76c50c3210C5AaA9c39D53A4f95BFd8b1a3a19 | https://sepolia-rollup.arbitrum.io/rpc | |
| 16 | +| Chain Name | Address | RPC URL |
| 17 | +|------------------|--------------------------------------------|---------------------------------------------------------------| |
| 18 | +| optimism-sepolia | 0x2eE67fF5d8548fF544f2c178a0FcAFe503A634Be | https://endpoints.omniatech.io/v1/op/sepolia/public |
| 19 | +| arbitrum-sepolia | 0xCd76c50c3210C5AaA9c39D53A4f95BFd8b1a3a19 | https://endpoints.omniatech.io/v1/arbitrum/sepolia/public |
24 | 20 | ```
|
25 | 21 |
|
| 22 | +NOTE: We recommend using your own RPC URL for the best experience. |
| 23 | + |
26 | 24 | You will also need the private key of a wallet with some gas tokens for your chosen network.
|
27 | 25 | Then, from the `coin_flip/app` directory, run the following command:
|
28 | 26 |
|
29 | 27 | ```
|
| 28 | +npm i |
| 29 | +
|
30 | 30 | npm run flip-coin -- \
|
31 | 31 | --private-key <hexadecimal evm private key> \
|
32 | 32 | --address <address> \
|
| 33 | + --chain-name <chain name> \ |
33 | 34 | --rpc-url <rpc url>
|
34 | 35 | ```
|
35 | 36 |
|
36 | 37 | You can populate the arguments to this command from the table above.
|
37 | 38 | The command should print output like this:
|
38 | 39 |
|
39 | 40 | ```text
|
40 |
| -Running coin flip prototcol. |
41 | 41 | 1. Generating user's random number...
|
42 |
| - number : 0x7c94c33d424e0a683deb15b55cc7d40d5cc8154478c76c971b677c35e32cb2f4 |
| 42 | +User Generated Random number: 0xcf29f434d1e80db1b6c650cd52ceab837131f02e68880beee71ee5c061fe8a5d |
| 43 | +
|
43 | 44 | 2. Requesting coin flip...
|
44 |
| - fee : 101 wei |
45 |
| - tx : 0x23e8e1c800d2e9c55d7e8bf1b2bd5e835979c1aa076f56ab4a74828a45684d9b |
46 |
| - sequence : 37 |
47 |
| -3. Waiting for result... |
48 |
| - result : Tails |
| 45 | +Flip Fee: 15000000000001 wei |
| 46 | +
|
| 47 | +3. Sending request to flip coin... |
| 48 | +
|
| 49 | +Transaction Hash: 0x3400f8e6146734afeae875e9aef1eee708e0843bb044e4b2c8dc7fc53d20020f |
| 50 | +
|
| 51 | +Polling Block: 16451104 |
| 52 | +Flip Request Number/ Sequence Number: 750 |
| 53 | +
|
| 54 | +Receipt Block Number: 16451104 |
| 55 | +
|
| 56 | +Polling Block: 16451106 |
| 57 | +
|
| 58 | +Flip Result: Heads |
49 | 59 | ```
|
50 | 60 |
|
51 | 61 | ## Understanding the Example
|
|
0 commit comments