You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/entropy/generate-random-numbers/evm.mdx
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ The Solidity SDK exports two interfaces:
39
39
-[`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.
40
40
You will need the address of an Entropy contract on your blockchain.
41
41
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:
43
43
44
44
```solidity copy
45
45
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
@@ -62,12 +62,12 @@ To generate a random number, follow these steps.
62
62
63
63
### 1. Request a number from Entropy
64
64
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.
67
67
68
68
The fee differs for every chain and also varies over time depending on the chain's current gas price.
69
69
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.
71
71
72
72
These methods use the default randomness provider ([see here](#randomness-providers) for more info on providers).
73
73
@@ -83,11 +83,25 @@ function requestRandomNumber() external payable {
83
83
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.
84
84
85
85
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
+
<Callouttype="info"emoji="ℹ️">
88
+
Users can also request a random 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 {
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).
87
101
88
102
### 2. Implement the Entropy callback
89
103
90
-
```solidity {28-42} copy
104
+
```solidity {31-45} copy
91
105
pragma solidity ^0.8.0;
92
106
93
107
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
@@ -133,7 +147,7 @@ contract YourContract is IEntropyConsumer {
133
147
}
134
148
}
135
149
136
-
```
150
+
````
137
151
138
152
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.
0 commit comments