Skip to content
Merged
Changes from 1 commit
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
66 changes: 50 additions & 16 deletions pages/entropy/generate-random-numbers/evm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,55 @@ contract YourContract is IEntropyConsumer {

## Usage

### requestV2 Variants

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:

#### 1. Basic Request

```solidity copy
function requestV2() external payable returns (uint64 assignedSequenceNumber);

```

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.

#### 2. Request with Gas Limit

```solidity copy
function requestV2(
uint32 gasLimit
) external payable returns (uint64 assignedSequenceNumber);

```

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.

#### 3. Request with Provider and Gas Limit

```solidity copy
function requestV2(
address provider,
uint32 gasLimit
) external payable returns (uint64 assignedSequenceNumber);

```

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.

#### 4. Request with Provider, User Randomness and Gas Limit

```solidity copy
function requestV2(
address provider,
bytes32 userRandomNumber,
uint32 gasLimit
) external payable returns (uint64 assignedSequenceNumber);

```

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.

To generate a random number, follow these steps.

### 1. Request a number from Entropy
Expand All @@ -82,21 +131,6 @@ 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
Expand Down Expand Up @@ -147,7 +181,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