API3 QRNG don't work

After triggering random number generation request (successfully) API3 QRNG airnode do note generate response transaction and inject random number.

My EOA address - 0x9B067169a817126115c27d4C460a32F64C435149 .

Sponsor wallet address - 0x6AB54b01e544c8FA6bF53AcC3606419cf99917C9 .

Demo contract address - 0x9651826A24f9A001b2e7fD414982C1f97C70cA36 .

For testing purpose I am using the real Fanto Opera. Mentioned demo contract was copied from API3 QRNG official documentation.

//SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import “@api3/airnode-protocol/contracts/rrp/requesters/RrpRequesterV0.sol”;

contract RemixQrng is RrpRequesterV0 {
event RequestedUint256(bytes32 indexed requestId);
event ReceivedUint256(bytes32 indexed requestId, uint256 response);

address public airnode;
bytes32 public endpointIdUint256;
address public sponsorWallet;
mapping(bytes32 => bool) public waitingFulfillment;

// These are for Remix demonstration purposes, their use is not practical.
struct LatestRequest { 
  bytes32 requestId;
  uint256 randomNumber;
}
LatestRequest public latestRequest;

constructor(address _airnodeRrp) RrpRequesterV0(_airnodeRrp) {}

// Normally, this function should be protected, as in:
// require(msg.sender == owner, "Sender not owner");
function setRequestParameters(
    address _airnode,
    bytes32 _endpointIdUint256,
    address _sponsorWallet
) external {
    airnode = _airnode;
    endpointIdUint256 = _endpointIdUint256;
    sponsorWallet = _sponsorWallet;
}

function makeRequestUint256() external {
    bytes32 requestId = airnodeRrp.makeFullRequest(
        airnode,
        endpointIdUint256,
        address(this),
        sponsorWallet,
        address(this),
        this.fulfillUint256.selector,
        ""
    );
    waitingFulfillment[requestId] = true;
    latestRequest.requestId = requestId;
    latestRequest.randomNumber = 0;
    emit RequestedUint256(requestId);
}

function fulfillUint256(bytes32 requestId, bytes calldata data)
    external
    onlyAirnodeRrp
{
    require(
        waitingFulfillment[requestId],
        "Request ID not known"
    );
    waitingFulfillment[requestId] = false;
    uint256 qrngUint256 = abi.decode(data, (uint256));
    // Do what you want with `qrngUint256` here...
    latestRequest.randomNumber = qrngUint256;
    emit ReceivedUint256(requestId, qrngUint256);
}

}

Hey, try funding Address 0x6ab54b01e544c8fa6bf53acc3606419cf99917c9 | FtmScan with an additional 0.1 FTM and sending another request. It looks like you successfully requested and received a few random numbers, but you stopped getting responses after your sponsor wallet balance went below the required amount for the 500,000 gas limit. I also confirmed that it’s currently working on Fantom.

Thanks for your advice, it seems to be working. Could you be more detailed about 500 000 gas limit? I can’t find it in docs.

I believe that is just the gas limit required for the fulfill function that Airnode must call.

This value for fulfillmentGasLimit is set in Airnode’s config.json file as described here: config.json | Documentation. The number 500,000 is set to be rather conservative for most chains, but the recommended amount varies; for some Layer 2s like Arbitrum it should be even higher.

Thank you for detailed explanation.

1 Like