简体   繁体   English

为什么我收到以下 Chainlink 错误:无法估计气体

[英]Why am I receiving the following Chainlink error: cannot estimate gas

I am trying to follow the Chainlink VRF tutorial found here: https://docs.chain.link/docs/intermediates-tutorial/ with hardhat and am running into this issue when calling the rollDice function:我正在尝试按照此处找到的 Chainlink VRF 教程进行操作: https ://docs.chain.link/docs/intermediates-tutorial/ with hardhat 并且在调用 rollDice 函数时遇到了这个问题:

Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","transaction":{"from":"0x014Da1D627E6ceB555975F09D26B048644382Ac6","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x9502f900"},"maxFeePerGas":{"type":"BigNumber","hex":"0x9502f90e"},"to":"0x5887946875A01D1BB79d6Fb357BceeA5A0096D2e","data":"0xdd02d9e5000000000000000000000000014da1d627e6ceb555975f09d26b048644382ac6","type":2,"accessList":null}}, tx={"data":"0xdd02d9e5000000000000000000000000014da1d627e6ceb555975f09d26b048644382ac6","to":{},"from":"0x014Da1D627E6ceB555975F09D26B048644382Ac6","type":2,"maxFeePerGas":{"type":"BigNumber","hex":"0x9502f90e"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x9502f900"},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.5.0)
    at Logger.makeError (/Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at /Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/abstract-signer/src.ts/index.ts:301:31
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 7)

I am able to deploy to the Kovan testnet, I was able to verify the contract, and I have sent the contract LINK tokens, but am still running into the issue.我能够部署到 Kovan 测试网,我能够验证合同,并且我已经发送了合同 LINK 令牌,但仍然遇到了问题。 The contract can be viewed here: https://kovan.etherscan.io/address/0x7b72d80670512c87605ab8ac7e6113fda9c57de4#code合约可以在这里查看: https : //kovan.etherscan.io/address/0x7b72d80670512c87605ab8ac7e6113fda9c57de4#code

I am using version 0.8 of the Chainlink Contracts.我正在使用 Chainlink 合约的 0.8 版。

RandomDay.sol随机日.sol

pragma solidity ^0.8.9;

import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

contract RandomDay is VRFConsumerBase {
    
    uint256 private constant ROLL_IN_PROGRESS = 42;
    bytes32 private s_keyHash;
    uint256 private s_fee;

    mapping(bytes32 => address) private s_rollers;
    mapping(address => uint256) private s_results;

    event DiceRolled(bytes32 indexed requestId, address indexed roller);
    event DiceLanded(bytes32 indexed requestId, uint256 indexed result);

    constructor(address vrfCoordinator, address link, bytes32 keyHash, uint256 fee) VRFConsumerBase(vrfCoordinator, link) {
        s_keyHash = keyHash;
        s_fee = fee;
   
    }

    function rollDice (address roller) public returns (bytes32 requestId) {
        require(LINK.balanceOf(address(this)) >= s_fee, "Not enough LINK to pay fee");
        require(s_results[roller] == 0, "Already rolled");
        requestId = requestRandomness(s_keyHash, s_fee);
        s_rollers[requestId] = roller;
        s_results[roller] = ROLL_IN_PROGRESS;
        emit DiceRolled(requestId, roller);
        return requestId;
    }

    function fulfillRandomness (bytes32 requestId, uint256 randomness) internal override {
        uint256 dayOfWeek = (randomness % 7) + 1;
        s_results[s_rollers[requestId]] = dayOfWeek;
        emit DiceLanded(requestId, dayOfWeek);
    }

    function weekday (address player) public view returns (string memory) {
        require(s_results[player] != 0, "Dice not rolled");
        require(s_results[player] != ROLL_IN_PROGRESS, "Roll in progress");
        return getWeekdayName(s_results[player]);
    }

    function getWeekdayName (uint256 id) private pure returns (string memory) {
        string[7] memory weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        return weekdays[id - 1];
    }

}

hardhat.config.js安全帽.config.js

/**
 * @type import('hardhat/config').HardhatUserConfig
 */

 require("@nomiclabs/hardhat-waffle")
 require("@nomiclabs/hardhat-etherscan")

 const ALCHEMY_API_KEY = "*************************";
 const ROPSTEN_PRIVATE_KEY = "*********************";
 
 module.exports = {
   solidity: "0.8.9",
   networks: {
     kovan: {
       url: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
       accounts: [`0x${ROPSTEN_PRIVATE_KEY}`],
       gas: 2700000000,
       maxFeePerGas: 30000000000,
     }
   },
   etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://etherscan.io/
    apiKey: "****************************"
  }
 };

deploy.js部署.js

const { ethers } = require("hardhat");

async function main() {
    const [deployer] = await ethers.getSigners();
  
    console.log("Deploying contracts with the account:", deployer.address);
  
    console.log("Account balance:", (await deployer.getBalance()).toString());
  
    const Token = await ethers.getContractFactory("RandomDay");
    const token = await Token.deploy("0xa36085F69e2889c224210F603D836748e7dC0088", "0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9", "0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4", "100000000000000000");
  
    console.log("Token address:", token.address); 
  }
  
  main()
    .then(() => process.exit(0))
    .catch((error) => {
      console.error(error);
      process.exit(1);
    });

quickRun.js快速运行.js

var ethers = require('ethers');
var provider = ethers.providers.getDefaultProvider('kovan');
var address  = '0x7b72d80670512c87605aB8aC7E6113Fda9c57de4';
var abi = [{"inputs":[{"internalType":"address","name":"vrfCoordinator","type":"address"},{"internalType":"address","name":"link","type":"address"},{"internalType":"bytes32","name":"keyHash","type":"bytes32"},{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"result","type":"uint256"}],"name":"DiceLanded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"roller","type":"address"}],"name":"DiceRolled","type":"event"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"},{"internalType":"uint256","name":"randomness","type":"uint256"}],"name":"rawFulfillRandomness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"roller","type":"address"}],"name":"rollDice","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"player","type":"address"}],"name":"weekday","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}];
var privateKey = '*******************************';
var wallet = new ethers.Wallet(privateKey, provider);
var contract = new ethers.Contract(address, abi, wallet);

var sendPromise = contract.rollDice('0x014Da1D627E6ceB555975F09D26B048644382Ac6');

sendPromise.then(function(transaction){
  console.log(transaction);
});

I believe the addresses are off:我相信地址是关闭的:

Constructor Arguments of your contract: -----Decoded View--------------- Arg [0] : vrfCoordinator (address): 0xa36085f69e2889c224210f603d836748e7dc0088 Arg [1] : link (address): 0xdd3782915140c8f3b190b5d67eac6dc5760c46e9 Arg [2] : keyHash (bytes32): 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4 Arg [3] : fee (uint256): 100000000000000000您的合约的构造函数参数:-----Decoded View------------------------- Arg [0] : vrfCoordinator (address): 0xa36085f69e2889c224210f603d836748e7dc0088 Arg [1] : link (address): 0x151467dc0dc6e6c0d6c6dc9d6c6d6c6dc6dc6d6c6dc6dc6dc6d6c6dc6d6c6d6c6dc6d6c6dc6d6c6e28820参数 [2] : keyHash (bytes32): 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4 参数 [3] : 费用 (uint2000000000000000000000x0x6c36c30001)

Via Chainlinks Docs:通过 Chainlinks 文档:

LINK 0xa36085F69e2889c224210F603D836748e7dC0088 VRF Coordinator 0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9 Key Hash 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4 Fee 0.1 LINK LINK 0xa36085F69e2889c224210F603D836748e7dC0088 VRF协调员0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9密钥散列0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4费0.1 LINK

Switched Link and VRF are probably the culprit. Switched Link 和 VRF 可能是罪魁祸首。

9 out of 10 is because you passed something wrong in the constructor or something in the contructor is not initialized propertly. 10 个中有 9 个是因为您在构造函数中传递了错误的内容,或者构造函数中的某些内容未正确初始化。 this kind of things aren't detected by compiler.编译器不会检测到这种事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到这个错误? “气体估计错误,显示以下消息(见下文)。 交易 > 执行可能会失败” - Why am I getting this error ? “Gas estimation errored with the following message (see below). The transaction > execution will likely fail” 进行交易时的 Solidity 错误 - 无法估算气体; 交易可能会失败或可能需要手动限制气体 - Solidity Error when doing a transaction - cannot estimate gas; transaction may fail or may require manual gas limit 无法弄清楚为什么在处理事务时出现 VM 异常:恢复错误 - Cannot figure out why I am getting VM Exception while processing transaction: revert error Chainlink vrf v2 请求 gas 费用金额 - Chainlink vrf v2 request gas fee amount 我应该如何使用chainlink keeper - how should i use chainlink keeper 为 swapExactTokensForTokens 估算 gas 时出错 - Error on estimating gas for swapExactTokensForTokens 为什么我总是收到“返回的值无效,它是否耗尽了 Gas”? - Why do I always get “Returned values are not valid, did it run Out of Gas”? 无法从chainlink节点终端远程连接到我的PostgreSQL服务器 - Cannot connect to my PostgreSQL server remotely from chainlink node terminal 为什么解析json路径数组时Chainlink作业出错 - Why Chainlink job errored when parsejson array of path CHAINLINK 节点 - 您的节点过载并可能开始丢失作业错误 - CHAINLINK NODE - Your node is overloaded and may start missing jobs ERROR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM