You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Run `node -v` to confirm. You should get an output with version >= `v18.0.0`.
11
+
-[Node](https://nodejs.org/en/download). Run `node -v{:jsx}` to confirm. You should get an output with version >= `v18.0.0`.
16
12
17
13
## Getting Started
18
14
19
-
Create a directory named `coin-flip` in your filesystem. Open a terminal with `coin-flip` as the working directory and run `forge init contracts` to create a new Solidity project. You will see a new directory in `coin-flip` named `contracts`. `contracts/src` is where all your contract code will be.
15
+
Create a directory named `coin-flip{:bash}` in your filesystem.
16
+
Open a terminal with `coin-flip` as the working directory and run `forge init contracts` to create a new Solidity project.
17
+
You will see a new directory in `coin-flip` named `contracts`. `contracts/src` is where all your contract code will be.
20
18
21
-
Run `cd contracts` to make it your terminal’s working directory — the following commands will need to be run from here.
19
+
```bash copy
20
+
mkdir coin-flip
21
+
cd coin-flip
22
+
forge init contracts
23
+
```
22
24
25
+
Run `cd contracts` to make it your terminal's working directory — the following commands will need to be run from here.
23
26
Next, install the Pyth Entropy SDK by running the following commands.
24
27
25
28
```bash copy
29
+
cd contracts
26
30
npm init -y
27
31
npm install @pythnetwork/entropy-sdk-solidity
28
32
```
@@ -35,22 +39,24 @@ Add a `remappings.txt` file to `contracts` directory with the following content.
35
39
36
40
## Implementation
37
41
38
-
Create a new file `CoinFlip.sol` in `contracts/src` directory and add the following code into it to start
42
+
Create a new file `CoinFlip.sol{:solidity}` in `contracts/src` directory and add the following code into it to start.
// This method is required by the IEntropyConsumer interface
@@ -61,11 +67,13 @@ contract CoinFlip is IEntropyConsumer {
61
67
62
68
```
63
69
64
-
The code implements a`CoinFlip` contract which inherits the `IEntropyConsumer` interface. We have also defined some events, properties and a constructor to instantiate the contract. One of the properties is of type `IEntropy` which is an interface imported from the Entropy SDK.
70
+
The code implements a`CoinFlip` contract which inherits the `IEntropyConsumer` interface.
71
+
We have also defined some events, properties and a constructor to instantiate the contract.
72
+
One of the properties is of type `IEntropyV2` which is an interface imported from the Entropy SDK.
65
73
66
74
### Request a coin flip
67
75
68
-
Copy the following code into `CoinFlip.sol`.
76
+
Copy the following code into `CoinFlip.sol{:solidity}`.
69
77
70
78
```solidity copy
71
79
contract CoinFlip {
@@ -87,11 +95,14 @@ contract CoinFlip {
87
95
88
96
```
89
97
90
-
Users will invoke the `request` method to initiate a coin flip, paying a fee in the process. The method first retrieves the fee required to request a random number from Entropy. It then includes the fee in the `requestV2` method call to Entropy. Finally, the method emits a `FlipRequested` event with a `sequenceNumber`. This event is also defined in the code snippet above.
98
+
Users will invoke the `request` method to initiate a coin flip, paying a fee in the process.
99
+
The method first retrieves the fee required to request a random number from Entropy.
100
+
It then includes the fee in the `requestV2` method call to Entropy.
101
+
Finally, the method emits a `FlipRequested` event with a `sequenceNumber`. This event is also defined in the code snippet above.
91
102
92
103
### Handle the callback
93
104
94
-
Copy the following code into `CoinFlip.sol`.
105
+
Copy the following code into `CoinFlip.sol{:solidity}`.
0 commit comments