Skip to content

Commit 74f6fef

Browse files
authored
(chore) Refactor Entropy Coin Flip example (#25)
* wip * final version * final version * updated * final version * final version
1 parent 5260110 commit 74f6fef

File tree

7 files changed

+7821
-93
lines changed

7 files changed

+7821
-93
lines changed

entropy/coin_flip/README.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
11
# Coin Flip Example application
22

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.
45

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.
87

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.
139

14-
These commands will build dependencies for the typescript project.
10+
## Try it out
1511

16-
Next, choose a network to run the example on.
12+
First, you have to choose a network to run the example on.
1713
The example has been deployed on the following networks:
1814

1915
```
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
2420
```
2521

22+
NOTE: We recommend using your own RPC URL for the best experience.
23+
2624
You will also need the private key of a wallet with some gas tokens for your chosen network.
2725
Then, from the `coin_flip/app` directory, run the following command:
2826

2927
```
28+
npm i
29+
3030
npm run flip-coin -- \
3131
--private-key <hexadecimal evm private key> \
3232
--address <address> \
33+
--chain-name <chain name> \
3334
--rpc-url <rpc url>
3435
```
3536

3637
You can populate the arguments to this command from the table above.
3738
The command should print output like this:
3839

3940
```text
40-
Running coin flip prototcol.
4141
1. Generating user's random number...
42-
number : 0x7c94c33d424e0a683deb15b55cc7d40d5cc8154478c76c971b677c35e32cb2f4
42+
User Generated Random number: 0xcf29f434d1e80db1b6c650cd52ceab837131f02e68880beee71ee5c061fe8a5d
43+
4344
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
4959
```
5060

5161
## Understanding the Example

0 commit comments

Comments
 (0)