Skip to content

Commit efb003e

Browse files
committed
chore(dev-docs): update entropy edits
1 parent 19be573 commit efb003e

File tree

6 files changed

+81
-80
lines changed

6 files changed

+81
-80
lines changed

apps/developer-hub/content/docs/entropy/debug-callback-failures.mdx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,70 @@
22
title: Debug Callback Failures
33
description: How to identify and resolve issues with Entropy callbacks
44
---
5+
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
56

6-
# Debug Callback Failures
7+
This guide explains how to identify and resolve issues with the Entropy callback.
8+
The intended audience for this guide is developers who have made an Entropy random number request, but their application hasn't received a callback.
79

810
> 🔍 **Quick Debug Tool**
11+
>
912
> Use the [Entropy Explorer](https://entropy-debugger.pyth.network/) to quickly diagnose and resolve callback issues.
1013
11-
This guide explains how to identify and resolve issues with the Entropy callback.
12-
The intended audience for this guide is developers who have made an Entropy random number request, but their application hasn't received a callback.
1314

1415
## Dependencies
1516

1617
This guide uses [Foundry](https://book.getfoundry.sh/getting-started/installation) to submit transactions to the blockchain.
1718
Please install Foundry before continuing.
18-
1919
## Run the Callback
2020

2121
Developers can run the Entropy callback themselves to see the reason for the failure.
2222
To run the callback, invoke the `revealWithCallback` function on the Entropy contract on your blockchain.
2323
The function has the following signature:
2424

25-
```solidity
26-
function revealWithCallback(
25+
<DynamicCodeBlock lang="solidity"
26+
code={`function revealWithCallback(
2727
address provider,
2828
uint64 sequenceNumber,
29-
bytes32 userRandomNumber,
30-
bytes32 providerRevelation
29+
bytes32 userContribution,
30+
bytes32 providerContribution
3131
)
32-
```
32+
`} />
3333

34-
This call requires the chain ID, contract address, and four arguments.
34+
This call requires the chain ID, contract address, and four other arguments.
3535
The chain ID and contract address can be retrieved from [Contract Addresses](contract-addresses).
3636
Export these values as environment variables for later use:
3737

38-
```bash
39-
export CHAIN_ID=blast
38+
<DynamicCodeBlock lang="bash"
39+
code={`export CHAIN_ID=blast
4040
export ENTROPY_ADDRESS=0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb
41-
```
41+
`} />
4242

43-
Three of the arguments can be retrieved from the request transaction's event logs.
43+
Three of the other arguments can be retrieved from the request transaction's event logs.
4444
Look at the event logs of the request transaction in a block explorer.
4545
You should see a `RequestedWithCallback` event emitted from the Entropy contract.
4646

4747
Copy the following values from the event into environment variables:
4848

49-
```bash
50-
export PROVIDER=0x52DeaA1c84233F7bb8C8A45baeDE41091c616506
49+
<DynamicCodeBlock lang="bash"
50+
code={`export PROVIDER=0x52DeaA1c84233F7bb8C8A45baeDE41091c616506
5151
export SEQUENCE_NUMBER=12345
5252
export USER_RANDOM_NUMBER=0x1234...
53-
```
53+
`} />
5454

55-
The fourth argument (provider revelation) must be retrieved from the provider's API.
55+
The fourth argument (provider contribution) must be retrieved from the provider's API.
5656
This value becomes available after the reveal delay has passed.
5757

5858
## Common Issues
5959

60+
There are a few common issues that can cause the callback to fail.
61+
6062
### Gas Limit Exceeded
6163

6264
If your callback function uses too much gas, the transaction will fail. Check the gas limit for your chain on the [contract addresses](contract-addresses) page and ensure your callback function uses less gas.
6365

66+
> 💡 **Tip**
67+
> Refer to the [Set Custom Gas Limits](set-custom-gas-limits) guide to set a custom gas limit for your callback function.
68+
6469
### Callback Function Errors
6570

6671
Your callback function might contain logic that throws an error. Review your callback implementation for:
@@ -73,3 +78,4 @@ Your callback function might contain logic that throws an error. Review your cal
7378
### Transaction Timing
7479

7580
Make sure you're attempting the callback after the reveal delay has passed. The reveal delay varies by network and helps prevent MEV attacks.
81+
Refer to the [Contract Addresses](contract-addresses) page for the reveal delay for each network.

apps/developer-hub/content/docs/entropy/generate-random-numbers-evm.mdx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Learn how to integrate Pyth Entropy to generate random numbers in y
44
---
55

66
import { Step, Steps } from "fumadocs-ui/components/steps";
7+
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
78

89
This guide explains how to integrate Pyth Entropy into EVM Contracts to generate on-chain random numbers.
910
The intended audience for this guide is developers of any application that needs on-chain randomness, such as NFT mints or games.
@@ -15,21 +16,19 @@ Install the SDK using your package manager:
1516

1617
<Tabs items={['hardhat', 'foundry']}>
1718
<Tab value="hardhat">
18-
```shell copy
19-
npm install @pythnetwork/entropy-sdk-solidity
20-
```
19+
<DynamicCodeBlock lang="shell"
20+
code={`npm install @pythnetwork/entropy-sdk-solidity`} />
2121
</Tab>
2222
<Tab value="foundry">
23-
```shell copy
24-
npm init -y
23+
<DynamicCodeBlock lang="shell" code={`npm init -y
2524
npm install @pythnetwork/entropy-sdk-solidity
26-
```
25+
`} />
2726

2827
Then add the following line to your `remappings.txt` file:
2928

30-
```text copy
31-
@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity
32-
```
29+
<DynamicCodeBlock lang="text"
30+
code={`@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity
31+
`} />
3332

3433
</Tab>
3534
</Tabs>
@@ -44,8 +43,8 @@ The Solidity SDK exports two interfaces:
4443
Consult the current [Entropy contract addresses](../contract-addresses) to find the address on your chain.
4544
Once you have a contract address, instantiate an `console.log("IEntropyV2"){:bash}` contract in your solidity contract:
4645

47-
```solidity copy
48-
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
46+
<DynamicCodeBlock lang="solidity"
47+
code={`import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
4948
import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
5049
5150
// @param entropyAddress The address of the entropy contract.
@@ -56,16 +55,15 @@ contract YourContract is IEntropyConsumer {
5655
entropy = IEntropyV2(entropyAddress);
5756
}
5857
}
59-
60-
```
58+
`} />
6159

6260
## Usage
6361

6462
To generate a random number, follow these steps.
6563

6664
<Steps>
6765
<Step>
68-
### 1. Request a number from Entropy
66+
### Request a number from Entropy
6967

7068
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.
7169
The `console.log("requestV2"){:bash}` method requires paying a fee in native gas tokens which is configured per-provider.
@@ -76,14 +74,13 @@ However, you should use the on-chain method [`getFeeV2`](https://github.com/pyth
7674

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

79-
```solidity copy
80-
function requestRandomNumber() external payable {
77+
<DynamicCodeBlock lang="solidity"
78+
code={`function requestRandomNumber() external payable {
8179
uint256 fee = entropy.getFeeV2();
8280
8381
uint64 sequenceNumber = entropy.requestV2{ value: fee }();
8482
}
85-
86-
```
83+
`} />
8784

8885
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.
8986

@@ -94,10 +91,10 @@ Please see the method documentation in the [IEntropyV2 interface](https://github
9491
</Step>
9592
<Step>
9693

97-
### 2. Implement the Entropy callback
94+
### Implement the Entropy callback
9895

99-
```solidity {31-45} copy
100-
pragma solidity ^0.8.0;
96+
<DynamicCodeBlock lang="solidity"
97+
code={`pragma solidity ^0.8.0;
10198
10299
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
103100
import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
@@ -141,15 +138,14 @@ contract YourContract is IEntropyConsumer {
141138
return address(entropy);
142139
}
143140
}
144-
145-
```
141+
`} />
146142

147143
</Step>
148144
</Steps>
149145

150146
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.
151147

152-
<Callout type="info">
148+
<Callout variant="warning">
153149
The `entropyCallback` function on your contract should **never** return an
154150
error. If it returns an error, the keeper will not be able to invoke the
155151
callback. If you are having problems receiving the callback, please see
@@ -184,6 +180,6 @@ a keeper service for fullfilling requests.
184180

185181
You can get the default provider's address by calling the [`getDefaultProvider`](https://github.com/pyth-network/pyth-crosschain/blob/f8ebeb6af31d98f94ce73edade6da2ebab7b2456/target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol#L94) method:
186182

187-
```solidity copy
188-
address provider = entropy.getDefaultProvider();
189-
```
183+
<DynamicCodeBlock lang="solidity"
184+
code={`address provider = entropy.getDefaultProvider();
185+
`} />

apps/developer-hub/content/docs/entropy/set-custom-gas-limits.mdx

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ description: How to set custom gas limits for Entropy callbacks
44
---
55

66
import { Step, Steps } from "fumadocs-ui/components/steps";
7+
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
78

8-
Custom gas limits are useful when your callback function requires more gas than the default provider limit, or when you want to optimize gas costs for simpler callbacks.
9+
Custom gas limits are useful when your callback function requires more gas than the [default provider limit]TODO(../contract-addresses), or when you want to optimize gas costs for simpler callbacks.
910

1011
## Prerequisites
1112

@@ -30,8 +31,8 @@ You might need custom gas limits in these scenarios:
3031

3132
Instead of the basic `requestV2()` method, use the variant that accepts a `gasLimit` parameter:
3233

33-
```solidity copy
34-
function requestRandomNumberWithCustomGas(
34+
<DynamicCodeBlock lang="solidity"
35+
code={`function requestRandomNumberWithCustomGas(
3536
uint32 customGasLimit
3637
) external payable {
3738
// Calculate the fee for the custom gas limit
@@ -42,26 +43,25 @@ function requestRandomNumberWithCustomGas(
4243
4344
// Store the sequence number for tracking if needed
4445
}
45-
46-
```
46+
`} />
4747

4848
### 2. Calculate Fees with Custom Gas Limit
4949

5050
When using custom gas limits, you must use the `getFeeV2` variant that accepts a `gasLimit` parameter:
5151

52-
```solidity copy
53-
// Get fee for custom gas limit
52+
<DynamicCodeBlock lang="solidity"
53+
code={`// Get fee for custom gas limit
5454
uint256 fee = entropy.getFeeV2(customGasLimit);
5555
5656
// NOT: uint256 fee = entropy.getFeeV2(); // This uses default gas limit
57-
```
57+
`} />
5858

5959
### 3. Complete Example
6060

6161
Here's a complete example showing how to implement custom gas limits:
6262

63-
```solidity copy
64-
pragma solidity ^0.8.0;
63+
<DynamicCodeBlock lang="solidity"
64+
code={`pragma solidity ^0.8.0;
6565
6666
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
6767
import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
@@ -120,18 +120,17 @@ contract CustomGasLimitExample is IEntropyConsumer {
120120
return address(entropy);
121121
}
122122
}
123-
124-
```
123+
`} />
125124

126125
## Gas Limit Constraints
127126

128127
When setting custom gas limits, be aware of these constraints:
129128

130-
<Callout type="info" title="Gas Limit Rules">
131-
- Gas limits are automatically rounded up to the nearest multiple of 10,000. -
132-
Example: 19,000 becomes 20,000, 25,500 becomes 30,000. - The minimum gas limit
133-
is the provider's configured default limit. - The maximum gas limit is
134-
655,350,000 (uint16.max × 10,000).
129+
<Callout variant="info" header="Gas Limit Rules">
130+
Gas limits are automatically rounded up to the nearest multiple of **10,000**.
131+
Example: 19,000 becomes 20,000 25,500 becomes 30,000. The minimum gas limit
132+
is the provider's configured default limit. The maximum gas limit is
133+
655,350,000 (`uint16.max` \* 10,000).
135134
</Callout>
136135

137136
### Recommended Gas Limits
@@ -147,44 +146,44 @@ When setting custom gas limits, be aware of these constraints:
147146

148147
Test your callback function to determine the actual gas usage:
149148

150-
```solidity copy
151-
// In your tests, measure gas usage
149+
<DynamicCodeBlock lang="solidity"
150+
code={`// In your tests, measure gas usage
152151
uint256 gasStart = gasleft();
153152
// Your callback logic here
154153
uint256 gasUsed = gasStart - gasleft();
155154
console.log("Gas used:", gasUsed);
156-
```
155+
`} />
157156

158157
### 2. Add Safety Buffer
159158

160159
Always add a safety buffer to your estimated gas usage:
161160

162-
```solidity copy
163-
uint32 estimatedGas = 150000;
161+
<DynamicCodeBlock lang="solidity"
162+
code={`uint32 estimatedGas = 150000;
164163
uint32 safetyBuffer = 20000;
165164
uint32 customGasLimit = estimatedGas + safetyBuffer;
166-
```
165+
`} />
167166

168167
### 3. Handle Gas Limit Errors
169168

170169
Be prepared to handle cases where your gas limit is insufficient:
171170

172-
<Callout type="warning" emoji="⚠️">
173-
If your callback runs out of gas, the entropy provider will not be able to
174-
complete the callback. Always test your gas limits thoroughly and include
175-
adequate safety margins.
171+
<Callout variant="warning">
172+
If your callback **runs out of gas**, the entropy provider will **not** be able to
173+
complete the callback. Always test your gas limits thoroughly and include
174+
adequate safety margins.
176175
</Callout>
177176

178177
### 4. Consider Fee Implications
179178

180179
Higher gas limits result in higher fees. Balance your gas needs with cost considerations:
181180

182-
```solidity copy
183-
// Compare fees for different gas limits
181+
<DynamicCodeBlock lang="solidity"
182+
code={`// Compare fees for different gas limits
184183
uint256 defaultFee = entropy.getFeeV2();
185184
uint256 customFee = entropy.getFeeV2(customGasLimit);
186185
uint256 additionalCost = customFee - defaultFee;
187-
```
186+
`} />
188187

189188
## Troubleshooting
190189

apps/developer-hub/content/docs/entropy/whats-new-entropyv2.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: What's New in Entropy v2
33
description: New features and improvements in Entropy v2
44
icon: Sparkle
55
---
6+
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
67

78
## Key Improvements
89

@@ -23,16 +24,15 @@ Each of these request types is described in more detail with examples in [Reques
2324

2425
The new version offers more granular fee calculation:
2526

26-
```solidity
27-
// Get fee for default provider and gas limit
27+
<DynamicCodeBlock lang="solidity" code={`// Get fee for default provider and gas limit
2828
uint256 basicFee = entropy.getFeeV2();
2929
3030
// Get fee for custom gas limit
3131
uint256 customGasFee = entropy.getFeeV2(gasLimit);
3232
3333
// Get fee for specific provider and gas limit
3434
uint256 providerFee = entropy.getFeeV2(provider, gasLimit);
35-
```
35+
`} />
3636

3737
### 3. Enhanced Callback Status
3838

apps/developer-hub/src/app/(docs)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { docsOptions } from "../../config/layout.config";
55

66
export default function Layout({ children }: { children: ReactNode }) {
77
return (
8-
<DocsLayout {...docsOptions} containerProps={{ role: "none" }}>
8+
<DocsLayout {...docsOptions}>
99
{children}
1010
</DocsLayout>
1111
);

0 commit comments

Comments
 (0)