diff --git a/pages/entropy/create-your-first-entropy-app.mdx b/pages/entropy/create-your-first-entropy-app.mdx index 276569b1..8c0a71f9 100644 --- a/pages/entropy/create-your-first-entropy-app.mdx +++ b/pages/entropy/create-your-first-entropy-app.mdx @@ -6,28 +6,33 @@ In this tutorial we will implement and deploy a coin flip contract which will us Before we start, please make sure you have the following tools installed: -Foundry - [https://book.getfoundry.sh/getting-started/installation](https://book.getfoundry.sh/getting-started/installation). +- [Foundry](https://book.getfoundry.sh/getting-started/installation). -- 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)` - -Node (version > 18) - [https://nodejs.org/en/download](https://nodejs.org/en/download) - -- Run `node -v` to confirm. You should get an output with version >= `v18.0.0`. +- [Node](https://nodejs.org/en/download). Run `node -v{:jsx}` to confirm. You should get an output with version >= `v18.0.0`. ## Getting Started -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. +Create a directory named `coin-flip{:bash}` in your filesystem. +We will use this directory as the working directory for the rest of the tutorial. +Let's initialize a new project in `coin-flip{:bash}` by running `forge init contracts{:bash}`. + +This will create a new directory in `coin-flip{:bash}` named `contracts/src`, which will contain the smart contract code. -Run `cd contracts` to make it your terminal’s working directory — the following commands will need to be run from here. +```bash copy +mkdir coin-flip +cd coin-flip +forge init contracts +``` -Next, install the Pyth Entropy SDK by running the following commands. +Now we will install the Pyth Entropy SDK in the `contracts` directory. ```bash copy +cd contracts npm init -y npm install @pythnetwork/entropy-sdk-solidity ``` -Add a `remappings.txt` file to `contracts` directory with the following content. +Add a `remappings.txt` file to `contracts` directory with the following content to tell Foundry where to find the Pyth Entropy SDK. ```text copy @pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity @@ -35,11 +40,13 @@ Add a `remappings.txt` file to `contracts` directory with the following content. ## Implementation -Create a new file `CoinFlip.sol` in `contracts/src` directory and add the following code into it to start +Create a new file `CoinFlip.sol{:solidity}` in `contracts/src` directory and add the following code into it to start. ```solidity copy +// contracts/src/CoinFlip.sol // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; + import "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol"; import "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol"; @@ -47,10 +54,10 @@ contract CoinFlip is IEntropyConsumer { event FlipRequested(uint64 sequenceNumber); event FlipResult(uint64 sequenceNumber, bool isHeads); - IEntropy entropy; + IEntropyV2 entropy; constructor(address _entropy) { - entropy = IEntropy(_entropy); + entropy = IEntropyV2(_entropy); } // This method is required by the IEntropyConsumer interface @@ -61,11 +68,13 @@ contract CoinFlip is IEntropyConsumer { ``` -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. +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 `IEntropyV2` which is an interface imported from the Entropy SDK. ### Request a coin flip -Copy the following code into `CoinFlip.sol`. +Copy the following code into `CoinFlip.sol{:solidity}`. ```solidity copy contract CoinFlip { @@ -87,11 +96,14 @@ contract CoinFlip { ``` -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. +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{:bash}` method call to Entropy. +Finally, the method emits a `FlipRequested{:bash}` event with a `sequenceNumber`. This event is also defined in the code snippet above. ### Handle the callback -Copy the following code into `CoinFlip.sol`. +Copy the following code into `CoinFlip.sol{:solidity}`. ```solidity copy contract CoinFlip { @@ -176,7 +188,7 @@ Deployed to: 0x8676ba0Dd492AB9813BC21D5Dce318427d1d73ae Transaction hash: 0x2178aa6d402c94166a93e81822248d00dd003827675ebd49b3c542970f5a0189 ``` -Let’s export the coin flip contract address as environment variable for later use: +Let's export the coin flip contract address as environment variable for later use: ```bash copy export COINFLIP_ADDRESS=