Skip to content

chore(entropy) Update Gudie to V2 #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions pages/entropy/generate-random-numbers/evm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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).

Expand All @@ -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.

<Callout type="info" emoji="ℹ️">
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);
}

````
</Callout>

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";
Expand Down Expand Up @@ -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.

Expand Down
Loading