【问题标题】:"Execution reverted" error when I call createCollectible function on goerli testnet当我在 goerli 测试网上调用 createCollectible 函数时出现“执行恢复”错误
【发布时间】:2022-10-13 22:58:43
【问题描述】:

我是智能合约和 Solidity 编程的新手,我一直在尝试在 goerli 测试网上部署 NFT 合约。合约部署没有任何问题,但是当我尝试调用“createCollectible”函数时,出现以下错误:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted
{
"originalError": {
"code": 3,
"data": "0xf0019fe60000000000000000000000000000000000000000000000000000000000000c6a000000000000000000000000b54644506388a04187d943dbbbd3edbb3ee53094",
"message": "execution reverted"
}
}

这是我的合同:

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";

/**
 * @title The AdvandedCollectible contract
 * @notice A contract that mints an NFT
 */
contract AdvancedCollectible is ERC721, VRFConsumerBaseV2 {
    VRFCoordinatorV2Interface immutable COORDINATOR;
    LinkTokenInterface immutable LINKTOKEN;

    uint256 public tokenCounter;
    uint64 immutable s_subscriptionId;

    // 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 immutable s_keyhash;
    uint32 immutable s_numWords = 1;
    uint16 immutable s_requestConfirmations = 3;

    // 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 immutable s_callbackGasLimit = 100000;
    uint256 public s_requestId;
    uint256 public s_randomWords;
    address s_owner;
    enum Breed {
        PUG,
        SHIBA_INU,
        ST_BERNARD
    }
    mapping(uint256 => Breed) public tokenIdToBreed;
    mapping(uint256 => address) public requestIdToSender;
    event requestCollectible(uint256 indexed requestId, address requester);
    event breedAssigned(uint256 tokenId, Breed breed);

    constructor(
        address vrfCoordinator,
        address link,
        bytes32 keyhash,
        uint64 subscriptionId
    ) VRFConsumerBaseV2(vrfCoordinator) ERC721("Dogie", "DOG") {
        tokenCounter = 0;
        COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
        LINKTOKEN = LinkTokenInterface(link);
        s_keyhash = keyhash;
        s_owner = msg.sender;
        s_subscriptionId = subscriptionId;
    }

    modifier onlyOwner() {
        require(msg.sender == s_owner, "You are not the owner");
        _;
    }

    function createCollectible() public returns (uint256) {
        s_requestId = COORDINATOR.requestRandomWords(
            s_keyhash,
            s_subscriptionId,
            s_requestConfirmations,
            s_callbackGasLimit,
            s_numWords
        );
        requestIdToSender[s_requestId] = msg.sender;
        emit requestCollectible(s_requestId, msg.sender);
    }

    function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords)
        internal
        override
    {
        s_randomWords = randomWords[0];
        Breed breed = Breed(s_randomWords % 3);
        uint256 newTokenId = tokenCounter;
        tokenIdToBreed[newTokenId] = breed;
        emit breedAssigned(newTokenId, breed);
        address owner = requestIdToSender[requestId];
        _safeMint(owner, newTokenId);
        tokenCounter++;
    }

    function setTokenURI(uint256 tokenId, string memory _tokenURI) public {
        require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: Caller is not owner nor approved."
        );
        setTokenURI(tokenId, _tokenURI);
    }
}

有人知道我在这里做错了什么吗?

【问题讨论】:

    标签: ethereum solidity nft remix chainlink


    【解决方案1】:

    所以我意识到我错过了一个小而重要的步骤,那就是在我的订阅中添加一个消费者。 使用 Chainlink VRF V2,您需要创建一个订阅,向该订阅添加资金,并将您的合约作为消费者部署到的地址添加到订阅中。我没有做最后一步,这就是我的交易执行不断恢复的原因。

    【讨论】:

      猜你喜欢
      • 2021-04-08
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 2019-02-16
      • 1970-01-01
      • 2015-09-26
      • 2019-03-26
      相关资源
      最近更新 更多