在使用Chainlink提供的VRFConsumerBaseV2时,我得到了Gas Estimation failed错



错误:

ValueError:气体估计失败:"已恢复执行"。此交易可能会恢复。如果你想广播,你必须手动设置气体限制。

// SPDX-License-Identifier: MIT
// An example of a consumer contract that relies on a subscription for funding.
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
contract VRFv2Consumer is VRFConsumerBaseV2 {
VRFCoordinatorV2Interface COORDINATOR;
LinkTokenInterface LINKTOKEN;
// Your subscription ID.
uint64 s_subscriptionId;
// Rinkeby coordinator. For other networks,
// see https://docs.chain.link/docs/vrf-contracts/#configurations
address vrfCoordinator = 0x6168499c0cFfCaCD319c818142124B7A15E857ab;
// Rinkeby LINK token contract. For other networks,
// see https://docs.chain.link/docs/vrf-contracts/#configurations
address link = 0x01BE23585060835E02B77ef475b0Cc51aA1e0709;
// The gas lane to use, which specifies the maximum gas price to bump to.
// For a list of available gas lanes on each network,
// see https://docs.chain.link/docs/vrf-contracts/#configurations
bytes32 keyHash = 0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc;
// Depends on the number of requested values that you want sent to the
// fulfillRandomWords() function. Storing each word costs about 20,000 gas,
// so 100,000 is a safe default for this example contract. Test and adjust
// this limit based on the network that you select, the size of the request,
// and the processing of the callback request in the fulfillRandomWords()
// function.
uint32 callbackGasLimit = 100000;
// The default is 3, but you can set this higher.
uint16 requestConfirmations = 3;
// For this example, retrieve 2 random values in one request.
// Cannot exceed VRFCoordinatorV2.MAX_NUM_WORDS.
uint32 numWords =  2;
uint256[] public s_randomWords;
uint256 public s_requestId;
address s_owner;
constructor(uint64 subscriptionId) VRFConsumerBaseV2(vrfCoordinator) {
COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
LINKTOKEN = LinkTokenInterface(link);
s_owner = msg.sender;
s_subscriptionId = subscriptionId;
}
// Assumes the subscription is funded sufficiently.
function requestRandomWords() external onlyOwner {
// Will revert if subscription is not set and funded.
s_requestId = COORDINATOR.requestRandomWords(
keyHash,
s_subscriptionId,
requestConfirmations,
callbackGasLimit,
numWords
);
}

function fulfillRandomWords(
uint256, /* requestId */
uint256[] memory randomWords
) internal override {
s_randomWords = randomWords;
}
modifier onlyOwner() {
require(msg.sender == s_owner);
_;
}
}

我试图调用requestRandomWords((,但它显示了如上所述的错误。

我也在Remix上尝试过,但它在那里也运行不正常,并显示出类似的错误

错误:气体估计错误,显示以下消息(见下文(。事务执行可能会失败。是否要强制发送?执行还原{"原始错误":{"代码":3,"数据":0xf0019fe6000000000000000000000000000000000000003a000000000000000000000000771809c8d7f2d4fd3f87529bf3d6023b382ba754","消息":"执行还原"}}

我也遇到了这个错误,并意识到我没有将新部署的合同添加为"消费者;我的Chainlink VRF Subscription Manager。

您是否在部署时正确设置了s_subscriptionId

请参阅https://docs.chain.link/docs/chainlink-vrf/有关详细信息,或具体访问https://vrf.chain.link/以设置Subscription Manager。

您应该检查您的测试网,并从中替换关于vrfCoordinator和keyHash的配置https://docs.chain.link/docs/vrf/v2/supported-networks/#configurations

如果您想将其部署到bsc测试网,请尝试以下解决方案:

https://forum.openzeppelin.com/t/im-trying-to-deploy-a-contract-in-the-bsctestnet-but-i-never-got-the-supply-solved/22279/8

相关内容

  • 没有找到相关文章

最新更新