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
{{ message }}
This repository was archived by the owner on Nov 28, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: pages/entropy/generate-random-numbers/evm.mdx
+50-16Lines changed: 50 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,55 @@ contract YourContract is IEntropyConsumer {
58
58
59
59
## Usage
60
60
61
+
### requestV2 Variants
62
+
63
+
The [`IEntropyV2`](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/entropy_sdk/solidity/IEntropyV2.sol) interface provides multiple variants of the `requestV2` function:
64
+
65
+
#### 1. Basic Request
66
+
67
+
```solidity copy
68
+
function requestV2() external payable returns (uint64 assignedSequenceNumber);
69
+
70
+
```
71
+
72
+
This is the simplest variant that requests entropy using the default randomness provider and default gas settings. Uses in-contract PRNG for the user contribution to randomness. Use this when you want the most straightforward implementation and don't need to customize provider or gas parameters.
This variant allows you to specify a custom gas limit for the callback function execution. Uses in-contract PRNG for the user contribution. Use this when your `entropyCallback` function has complex logic that requires more gas than the default amount, or when you want to optimize gas usage by setting a lower limit for simple callbacks.
This variant allows you to specify both a custom randomness provider and a custom gas limit for the callback. Uses in-contract PRNG for the user contribution. Use this when you need full control over both the randomness source and the gas allocation for your callback execution.
96
+
97
+
#### 4. Request with Provider, User Randomness and Gas Limit
This is the most complete variant that allows you to specify a custom randomness provider, a custom gas limit for the callback, and provide your own user contribution to the randomness. The `userRandomNumber` parameter allows you to contribute your own randomness to the entropy generation process instead of relying on the in-contract PRNG. Use this when you need maximum control over all aspects of the randomness generation, including providing your own source of entropy for the user contribution.
109
+
61
110
To generate a random number, follow these steps.
62
111
63
112
### 1. Request a number from Entropy
@@ -82,21 +131,6 @@ function requestRandomNumber() external payable {
82
131
83
132
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
133
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).
101
135
102
136
### 2. Implement the Entropy callback
@@ -147,7 +181,7 @@ contract YourContract is IEntropyConsumer {
147
181
}
148
182
}
149
183
150
-
````
184
+
```
151
185
152
186
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