Skip to content

Commit 3a22daf

Browse files
committed
chore(entropy) Update Gudie to V2
1 parent e365ed3 commit 3a22daf

File tree

1 file changed

+21
-6
lines changed
  • pages/entropy/generate-random-numbers

1 file changed

+21
-6
lines changed

pages/entropy/generate-random-numbers/evm.mdx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The Solidity SDK exports two interfaces:
3939
- [`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.
4040
You will need the address of an Entropy contract on your blockchain.
4141
Consult the current [Entropy contract addresses](../contract-addresses) to find the address on your chain.
42-
Once you have a contract address, instantiate an `IEntropyV2` contract in your solidity contract:
42+
Once you have a contract address, instantiate an `IEntropyV2{:bash}` contract in your solidity contract:
4343

4444
```solidity copy
4545
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
@@ -62,12 +62,12 @@ To generate a random number, follow these steps.
6262

6363
### 1. Request a number from Entropy
6464

65-
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.
66-
The `requestV2` method requires paying a fee in native gas tokens which is configured per-provider.
65+
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.
66+
The `requestV2{:bash}` method requires paying a fee in native gas tokens which is configured per-provider.
6767

6868
The fee differs for every chain and also varies over time depending on the chain's current gas price.
6969
The current value for each chain can be found on the [Current Fees](../current-fees) page.
70-
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.
70+
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.
7171

7272
These methods use the default randomness provider ([see here](#randomness-providers) for more info on providers).
7373

@@ -83,11 +83,26 @@ function requestRandomNumber() external payable {
8383
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.
8484

8585
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.
86+
87+
<Callout type="info" emoji="ℹ️">
88+
Users can also request a number with a custom gas limit by passing a **custom `gasLimit`** to the `requestV2(uint32 gasLimit){:bash}` call.
89+
For example,
90+
```solidity copy
91+
function requestRandomNumber(uint32 gasLimit) external payable {
92+
uint256 fee = entropy.getFeeV2();
93+
94+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(gasLimit);
95+
}
96+
97+
````
8698
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).
8799
100+
</Callout>
101+
102+
88103
### 2. Implement the Entropy callback
89104
90-
```solidity {28-42} copy
105+
```solidity {31-45} copy
91106
pragma solidity ^0.8.0;
92107
93108
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
@@ -133,7 +148,7 @@ contract YourContract is IEntropyConsumer {
133148
}
134149
}
135150
136-
```
151+
````
137152
138153
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.
139154

0 commit comments

Comments
 (0)