Skip to content

Commit 679822f

Browse files
authored
Chore(entropy) update guide v2 (#769)
* chore(entropy) Update Guide V2 - Part1 * chore(entropy) Update Guide V2
1 parent e365ed3 commit 679822f

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

pages/entropy/create-your-first-entropy-app.mdx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,58 @@ In this tutorial we will implement and deploy a coin flip contract which will us
66

77
Before we start, please make sure you have the following tools installed:
88

9-
Foundry - [https://book.getfoundry.sh/getting-started/installation](https://book.getfoundry.sh/getting-started/installation).
9+
- [Foundry](https://book.getfoundry.sh/getting-started/installation).
1010

11-
- Run `forge --version` to confirm it is installed. You should get an output similar to `forge 0.2.0 (23aa303 2023-11-28T00:35:15.730515000Z)`
12-
13-
Node (version > 18) - [https://nodejs.org/en/download](https://nodejs.org/en/download)
14-
15-
- 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`.
1612

1713
## Getting Started
1814

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

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+
```
2226

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

2529
```bash copy
30+
cd contracts
2631
npm init -y
2732
npm install @pythnetwork/entropy-sdk-solidity
2833
```
2934

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

3237
```text copy
3338
@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity
3439
```
3540

3641
## Implementation
3742

38-
Create a new file `CoinFlip.sol` in `contracts/src` directory and add the following code into it to start
43+
Create a new file `CoinFlip.sol{:solidity}` in `contracts/src` directory and add the following code into it to start.
3944

4045
```solidity copy
46+
// contracts/src/CoinFlip.sol
4147
// SPDX-License-Identifier: UNLICENSED
4248
pragma solidity ^0.8.13;
49+
4350
import "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
4451
import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
4552
4653
contract CoinFlip is IEntropyConsumer {
4754
event FlipRequested(uint64 sequenceNumber);
4855
event FlipResult(uint64 sequenceNumber, bool isHeads);
4956
50-
IEntropy entropy;
57+
IEntropyV2 entropy;
5158
5259
constructor(address _entropy) {
53-
entropy = IEntropy(_entropy);
60+
entropy = IEntropyV2(_entropy);
5461
}
5562
5663
// This method is required by the IEntropyConsumer interface
@@ -61,11 +68,13 @@ contract CoinFlip is IEntropyConsumer {
6168
6269
```
6370

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

6675
### Request a coin flip
6776

68-
Copy the following code into `CoinFlip.sol`.
77+
Copy the following code into `CoinFlip.sol{:solidity}`.
6978

7079
```solidity copy
7180
contract CoinFlip {
@@ -87,11 +96,14 @@ contract CoinFlip {
8796
8897
```
8998

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

92104
### Handle the callback
93105

94-
Copy the following code into `CoinFlip.sol`.
106+
Copy the following code into `CoinFlip.sol{:solidity}`.
95107

96108
```solidity copy
97109
contract CoinFlip {
@@ -176,7 +188,7 @@ Deployed to: 0x8676ba0Dd492AB9813BC21D5Dce318427d1d73ae
176188
Transaction hash: 0x2178aa6d402c94166a93e81822248d00dd003827675ebd49b3c542970f5a0189
177189
```
178190

179-
Lets export the coin flip contract address as environment variable for later use:
191+
Let's export the coin flip contract address as environment variable for later use:
180192

181193
```bash copy
182194
export COINFLIP_ADDRESS=<Deployed to address from above>

0 commit comments

Comments
 (0)