Skip to content

Commit f2eae01

Browse files
committed
chore(entropy) Update Guide V2 - Part1
1 parent e365ed3 commit f2eae01

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ 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+
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.
2018

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

25+
Run `cd contracts` to make it your terminal's working directory — the following commands will need to be run from here.
2326
Next, install the Pyth Entropy SDK by running the following commands.
2427

2528
```bash copy
29+
cd contracts
2630
npm init -y
2731
npm install @pythnetwork/entropy-sdk-solidity
2832
```
@@ -35,22 +39,24 @@ Add a `remappings.txt` file to `contracts` directory with the following content.
3539

3640
## Implementation
3741

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

4044
```solidity copy
45+
// contracts/src/CoinFlip.sol
4146
// SPDX-License-Identifier: UNLICENSED
4247
pragma solidity ^0.8.13;
48+
4349
import "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
4450
import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
4551
4652
contract CoinFlip is IEntropyConsumer {
4753
event FlipRequested(uint64 sequenceNumber);
4854
event FlipResult(uint64 sequenceNumber, bool isHeads);
4955
50-
IEntropy entropy;
56+
IEntropyV2 entropy;
5157
5258
constructor(address _entropy) {
53-
entropy = IEntropy(_entropy);
59+
entropy = IEntropyV2(_entropy);
5460
}
5561
5662
// This method is required by the IEntropyConsumer interface
@@ -61,11 +67,13 @@ contract CoinFlip is IEntropyConsumer {
6167
6268
```
6369

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

6674
### Request a coin flip
6775

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

7078
```solidity copy
7179
contract CoinFlip {
@@ -87,11 +95,14 @@ contract CoinFlip {
8795
8896
```
8997

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

92103
### Handle the callback
93104

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

96107
```solidity copy
97108
contract CoinFlip {

0 commit comments

Comments
 (0)