From f2eae0121d186ece27a3e839b9805ad8508ad35e Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 24 Jul 2025 16:11:06 -0400 Subject: [PATCH 1/2] chore(entropy) Update Guide V2 - Part1 --- .../entropy/create-your-first-entropy-app.mdx | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/pages/entropy/create-your-first-entropy-app.mdx b/pages/entropy/create-your-first-entropy-app.mdx index 276569b1..065c11ba 100644 --- a/pages/entropy/create-your-first-entropy-app.mdx +++ b/pages/entropy/create-your-first-entropy-app.mdx @@ -6,23 +6,27 @@ 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. +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. -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 +``` +Run `cd contracts` to make it your terminal's working directory — the following commands will need to be run from here. Next, install the Pyth Entropy SDK by running the following commands. ```bash copy +cd contracts npm init -y npm install @pythnetwork/entropy-sdk-solidity ``` @@ -35,11 +39,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 +53,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 +67,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 +95,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` method call to Entropy. +Finally, the method emits a `FlipRequested` 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 { From 6b4ff770fa8420fd0b273ca54d491bf217ca3b85 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 24 Jul 2025 18:35:23 -0400 Subject: [PATCH 2/2] chore(entropy) Update Guide V2 --- pages/entropy/create-your-first-entropy-app.mdx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pages/entropy/create-your-first-entropy-app.mdx b/pages/entropy/create-your-first-entropy-app.mdx index 065c11ba..8c0a71f9 100644 --- a/pages/entropy/create-your-first-entropy-app.mdx +++ b/pages/entropy/create-your-first-entropy-app.mdx @@ -13,8 +13,10 @@ Before we start, please make sure you have the following tools installed: ## Getting Started Create a directory named `coin-flip{:bash}` 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. +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. ```bash copy mkdir coin-flip @@ -22,8 +24,7 @@ cd coin-flip forge init contracts ``` -Run `cd contracts` to make it your terminal's working directory — the following commands will need to be run from here. -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 @@ -31,7 +32,7 @@ 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 @@ -97,8 +98,8 @@ 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. +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 @@ -187,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=