diff --git a/pages/entropy/generate-random-numbers/evm.mdx b/pages/entropy/generate-random-numbers/evm.mdx index 09917d2a..84527756 100644 --- a/pages/entropy/generate-random-numbers/evm.mdx +++ b/pages/entropy/generate-random-numbers/evm.mdx @@ -39,7 +39,7 @@ The Solidity SDK exports two interfaces: - [`IEntropyV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropyV2.sol) - The interface to interact with the Entropy contract. You will need the address of an Entropy contract on your blockchain. Consult the current [Entropy contract addresses](../contract-addresses) to find the address on your chain. - Once you have a contract address, instantiate an `IEntropyV2` contract in your solidity contract: + Once you have a contract address, instantiate an `IEntropyV2{:bash}` contract in your solidity contract: ```solidity copy import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol"; @@ -62,12 +62,12 @@ To generate a random number, follow these steps. ### 1. Request a number from Entropy -Invoke the [`requestV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol#L83) method of the `IEntropyV2` contract. -The `requestV2` method requires paying a fee in native gas tokens which is configured per-provider. +Invoke the [`requestV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol#L83) method of the `IEntropyV2` interface. +The `requestV2{:bash}` method requires paying a fee in native gas tokens which is configured per-provider. The fee differs for every chain and also varies over time depending on the chain's current gas price. The current value for each chain can be found on the [Current Fees](../current-fees) page. -However, you should use the on-chain method [`getFeeV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol#L101) to compute the required fee and send it as the value of the `requestV2` call. +However, you should use the on-chain method [`getFeeV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol#L101) to compute the required fee and send it as the value of the `requestV2{:bash}` call. These methods use the default randomness provider ([see here](#randomness-providers) for more info on providers). @@ -83,11 +83,25 @@ function requestRandomNumber() external payable { This method returns a sequence number and emits a [`Requested`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/EntropyEventsV2.sol#L30) event. You can store this sequence number to identify the request in next step. Note that there are several variants of `requestV2` that allow the caller to configure the provider fulfilling the request and the gas limit for the callback. + + +Users can also request a random number with a custom gas limit by passing a **custom `gasLimit`** to the `requestV2(uint32 gasLimit){:bash}` call. +For example, +```solidity copy +function requestRandomNumber(uint32 gasLimit) external payable { + uint256 fee = entropy.getFeeV2(); + +uint64 sequenceNumber = entropy.requestV2{ value: fee }(gasLimit); +} + +```` + + Please see the method documentation in the [IEntropyV2 interface](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropyV2.sol). ### 2. Implement the Entropy callback -```solidity {28-42} copy +```solidity {31-45} copy pragma solidity ^0.8.0; import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol"; @@ -133,7 +147,7 @@ contract YourContract is IEntropyConsumer { } } -``` +```` When the final random number is ready to use, the entropyCallback function will be called by the Entropy contract. This will happen in a separate transaction submitted by the requested provider.