Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 7bf378c

Browse files
committed
add different variants of request v2
1 parent 3afc56c commit 7bf378c

File tree

1 file changed

+50
-16
lines changed
  • pages/entropy/generate-random-numbers

1 file changed

+50
-16
lines changed

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

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,55 @@ contract YourContract is IEntropyConsumer {
5858

5959
## Usage
6060

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.
73+
74+
#### 2. Request with Gas Limit
75+
76+
```solidity copy
77+
function requestV2(
78+
uint32 gasLimit
79+
) external payable returns (uint64 assignedSequenceNumber);
80+
81+
```
82+
83+
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.
84+
85+
#### 3. Request with Provider and Gas Limit
86+
87+
```solidity copy
88+
function requestV2(
89+
address provider,
90+
uint32 gasLimit
91+
) external payable returns (uint64 assignedSequenceNumber);
92+
93+
```
94+
95+
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
98+
99+
```solidity copy
100+
function requestV2(
101+
address provider,
102+
bytes32 userRandomNumber,
103+
uint32 gasLimit
104+
) external payable returns (uint64 assignedSequenceNumber);
105+
106+
```
107+
108+
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+
61110
To generate a random number, follow these steps.
62111

63112
### 1. Request a number from Entropy
@@ -82,21 +131,6 @@ function requestRandomNumber() external payable {
82131

83132
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.
84133

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-
<Callout type="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 {
92-
uint256 fee = entropy.getFeeV2();
93-
94-
uint64 sequenceNumber = entropy.requestV2{ value: fee }(gasLimit);
95-
}
96-
97-
````
98-
</Callout>
99-
100134
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).
101135

102136
### 2. Implement the Entropy callback
@@ -147,7 +181,7 @@ contract YourContract is IEntropyConsumer {
147181
}
148182
}
149183
150-
````
184+
```
151185

152186
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.
153187

0 commit comments

Comments
 (0)