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
+
We will use this directory as the working directory for the rest of the tutorial.
17
+
Let's initialize a new project in `coin-flip{:bash}` by running `forge init contracts{:bash}`.
18
+
19
+
This will create a new directory in `coin-flip{:bash}` named `contracts/src`, which will contain the smart contract code.
20
20
21
-
Run `cd contracts` to make it your terminal’s working directory — the following commands will need to be run from here.
21
+
```bash copy
22
+
mkdir coin-flip
23
+
cd coin-flip
24
+
forge init contracts
25
+
```
22
26
23
-
Next, install the Pyth Entropy SDK by running the following commands.
27
+
Now we will install the Pyth Entropy SDK in the `contracts` directory.
24
28
25
29
```bash copy
30
+
cd contracts
26
31
npm init -y
27
32
npm install @pythnetwork/entropy-sdk-solidity
28
33
```
29
34
30
-
Add a `remappings.txt` file to `contracts` directory with the following content.
35
+
Add a `remappings.txt` file to `contracts` directory with the following content to tell Foundry where to find the Pyth Entropy SDK.
// This method is required by the IEntropyConsumer interface
@@ -61,11 +68,13 @@ contract CoinFlip is IEntropyConsumer {
61
68
62
69
```
63
70
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.
71
+
The code implements a`CoinFlip` contract which inherits the `IEntropyConsumer` interface.
72
+
We have also defined some events, properties and a constructor to instantiate the contract.
73
+
One of the properties is of type `IEntropyV2` which is an interface imported from the Entropy SDK.
65
74
66
75
### Request a coin flip
67
76
68
-
Copy the following code into `CoinFlip.sol`.
77
+
Copy the following code into `CoinFlip.sol{:solidity}`.
69
78
70
79
```solidity copy
71
80
contract CoinFlip {
@@ -87,11 +96,14 @@ contract CoinFlip {
87
96
88
97
```
89
98
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.
99
+
Users will invoke the `request` method to initiate a coin flip, paying a fee in the process.
100
+
The method first retrieves the fee required to request a random number from Entropy.
101
+
It then includes the fee in the `requestV2{:bash}` method call to Entropy.
102
+
Finally, the method emits a `FlipRequested{:bash}` event with a `sequenceNumber`. This event is also defined in the code snippet above.
91
103
92
104
### Handle the callback
93
105
94
-
Copy the following code into `CoinFlip.sol`.
106
+
Copy the following code into `CoinFlip.sol{:solidity}`.
95
107
96
108
```solidity copy
97
109
contract CoinFlip {
@@ -176,7 +188,7 @@ Deployed to: 0x8676ba0Dd492AB9813BC21D5Dce318427d1d73ae
0 commit comments