Skip to content

Commit 510a549

Browse files
devin-ai-integration[bot]Jayant
andcommitted
fix: apply pre-commit formatting fixes
- Remove trailing whitespace - Apply prettier formatting to code blocks and content - Ensure compliance with repository style guidelines Co-Authored-By: Jayant <[email protected]>
1 parent df85d46 commit 510a549

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

pages/entropy/generate-random-numbers/set-custom-gas-limits.mdx

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ You might need custom gas limits in these scenarios:
2828
Instead of the basic `requestV2()` method, use the variant that accepts a `gasLimit` parameter:
2929

3030
```solidity copy
31-
function requestRandomNumberWithCustomGas(uint32 customGasLimit) external payable {
31+
function requestRandomNumberWithCustomGas(
32+
uint32 customGasLimit
33+
) external payable {
3234
// Calculate the fee for the custom gas limit
3335
uint256 fee = entropy.getFeeV2(customGasLimit);
34-
36+
3537
// Request random number with custom gas limit
36-
uint64 sequenceNumber = entropy.requestV2{value: fee}(customGasLimit);
37-
38+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
39+
3840
// Store the sequence number for tracking if needed
3941
}
42+
4043
```
4144

4245
### 2. Calculate Fees with Custom Gas Limit
@@ -63,32 +66,32 @@ import { IEntropyV2 } from "@pythnetwork/entropy-sdk-solidity/IEntropyV2.sol";
6366
contract CustomGasLimitExample is IEntropyConsumer {
6467
IEntropyV2 public entropy;
6568
mapping(uint64 => bool) public processedRequests;
66-
69+
6770
constructor(address entropyAddress) {
6871
entropy = IEntropyV2(entropyAddress);
6972
}
70-
73+
7174
// Request with custom gas limit for complex callback
7275
function requestComplexRandomNumber() external payable {
7376
uint32 customGasLimit = 200000; // Higher limit for complex operations
7477
uint256 fee = entropy.getFeeV2(customGasLimit);
75-
78+
7679
require(msg.value >= fee, "Insufficient fee");
77-
78-
uint64 sequenceNumber = entropy.requestV2{value: fee}(customGasLimit);
80+
81+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
7982
// Store sequence number if needed for tracking
8083
}
81-
84+
8285
// Request with lower gas limit for simple callback
8386
function requestSimpleRandomNumber() external payable {
8487
uint32 customGasLimit = 50000; // Lower limit for simple operations
8588
uint256 fee = entropy.getFeeV2(customGasLimit);
86-
89+
8790
require(msg.value >= fee, "Insufficient fee");
88-
89-
uint64 sequenceNumber = entropy.requestV2{value: fee}(customGasLimit);
91+
92+
uint64 sequenceNumber = entropy.requestV2{ value: fee }(customGasLimit);
9093
}
91-
94+
9295
// Complex callback that requires more gas
9396
function entropyCallback(
9497
uint64 sequenceNumber,
@@ -98,40 +101,40 @@ contract CustomGasLimitExample is IEntropyConsumer {
98101
// Prevent duplicate processing
99102
require(!processedRequests[sequenceNumber], "Already processed");
100103
processedRequests[sequenceNumber] = true;
101-
104+
102105
// Complex operations that require more gas
103106
for (uint i = 0; i < 10; i++) {
104107
// Simulate complex state changes
105108
// This would require more gas than the default limit
106109
}
107-
110+
108111
// Use the random number for your application logic
109112
uint256 randomValue = uint256(randomNumber);
110113
// Your application logic here...
111114
}
112-
115+
113116
function getEntropy() internal view override returns (address) {
114117
return address(entropy);
115118
}
116119
}
120+
117121
```
118122

119123
## Gas Limit Constraints
120124

121125
When setting custom gas limits, be aware of these constraints:
122126

123127
<Callout type="info" emoji="ℹ️">
124-
**Gas Limit Rules:**
125-
- Gas limits are automatically rounded up to the nearest multiple of 10,000
126-
- Example: 19,000 becomes 20,000, 25,500 becomes 30,000
127-
- The minimum gas limit is the provider's configured default limit
128-
- The maximum gas limit is 655,350,000 (uint16.max × 10,000)
128+
**Gas Limit Rules:** - Gas limits are automatically rounded up to the nearest
129+
multiple of 10,000 - Example: 19,000 becomes 20,000, 25,500 becomes 30,000 -
130+
The minimum gas limit is the provider's configured default limit - The maximum
131+
gas limit is 655,350,000 (uint16.max × 10,000)
129132
</Callout>
130133

131134
### Recommended Gas Limits
132135

133136
- **Simple callbacks**: 50,000 - 100,000 gas
134-
- **Moderate complexity**: 100,000 - 200,000 gas
137+
- **Moderate complexity**: 100,000 - 200,000 gas
135138
- **Complex operations**: 200,000 - 500,000 gas
136139
- **Very complex logic**: 500,000+ gas (use with caution)
137140

@@ -164,8 +167,8 @@ uint32 customGasLimit = estimatedGas + safetyBuffer;
164167
Be prepared to handle cases where your gas limit is insufficient:
165168

166169
<Callout type="warning" emoji="⚠️">
167-
If your callback runs out of gas, the entropy provider will not be able to
168-
complete the callback. Always test your gas limits thoroughly and include
170+
If your callback runs out of gas, the entropy provider will not be able to
171+
complete the callback. Always test your gas limits thoroughly and include
169172
adequate safety margins.
170173
</Callout>
171174

0 commit comments

Comments
 (0)