简体   繁体   English

接口。 为什么在尝试使用外部 function 时出现类型错误?

[英]Interfaces. Why am I getting a type error when trying to use an external function?

Here is the code for my main smart contract.这是我的主要智能合约的代码。 Errors on the last two functions.最后两个函数的错误。

from solidity: TypeError: Invalid type for argument in function call.来自solidity:TypeError:function调用中的参数类型无效。 Invalid implicit conversion from type(uint256) to uint256 requested.请求的从 type(uint256) 到 uint256 的隐式转换无效。 --> contracts/DIV4.sol:39:57: | --> 合约/DIV4.sol:39:57: | 39 | 39 | randomness_interface(_random).fulfillRandomness(uint256); randomness_interface(_random).fulfillRandomness(uint256); | | ^^^^^^ ^^^^^^

from solidity: TypeError: Invalid type for argument in function call.来自solidity:TypeError:function调用中的参数类型无效。 Invalid implicit conversion from type(bytes32) to bytes32 requested.请求的从 type(bytes32) 到 bytes32 的隐式转换无效。 --> contracts/DIV4.sol:43:55: | --> 合约/DIV4.sol:43:55: | 43 | 43 | randomness_interface(_random).getRandomNumber(bytes32); randomness_interface(_random).getRandomNumber(bytes32); | | ^^^^^^^ ^^^^^^^

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import {randomness_interface} from "./randomness_interface.sol";

contract Divergence is ERC1155, Ownable  {
    uint256 public constant One = 0;
    uint256 public constant Two = 1;
    uint256 public constant Three = 2;
    uint256 public constant Four = 3;
    
    constructor() ERC1155 ("https://ipfs.io/ipfs/dsfgijdsfklj348rue0ur099045948.json"){
        _mint(msg.sender, item1, 1000, "" );
        _mint(msg.sender, item2, 130, "" );
        _mint(msg.sender, item3, 65, "" );
        _mint(msg.sender, item4, 3, "" );
    }

    function uri(uint256 _tokenId) override public view returns (string memory) {
        return string(
            abi.encodePacked(
                "https://ipfs.io/ipfs/Qmf4WrTGA2fYJXitigvqJ7FDVMPreJQW4of8HZ1k5Wzkd3?filename=Divergence1",
                Strings.toString(_tokenId),
                ".json"
            )
        );
    }

    function generateRandomNumber(address _random) external(bytes32 requestId) {
        randomness_interface(_random).fulfillRandomness(uint256);
    }

    function getRandomNumberfromOutside(address _random) external {
        randomness_interface(_random).getRandomNumber(bytes32);
    }
   

Interface.sol file. Interface.sol 文件。


pragma solidity ^0.8.0;

interface randomness_interface {
    function fulfillRandomness(uint256 randomness) external view returns (uint);
    function getRandomNumber(bytes32 requestId) external;
}

Finally, the file with all the randomization happening.最后,所有随机化发生的文件。


pragma solidity ^0.6.6;


import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol";


contract RandomNumber is VRFConsumerBase {

    bytes32 public keyHash;
    uint256 public fee;
    uint256 public randomResult;

    constructor() VRFConsumerBase(0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, 0xa36085F69e2889c224210F603D836748e7dC0088) public {
        keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
        fee = 0.1 * 10 ** 18; //0.1 LINK
    }

    function getRandomNumber() public returns (bytes32 requestId) {
        return requestRandomness(keyHash, fee);
    }

    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness.mod(100).add(1);
    }


}

You are not passing correct arguments to the functions.您没有将正确的 arguments 传递给函数。

- -

 function generateRandomNumber(address _random) external(bytes32 requestId) {
        randomness_interface(_random).fulfillRandomness(uint256);
    }

You are calling randomness_interface(_random).fulfillRandomness and fulfillRandomness expects您正在调用randomness_interface(_random).fulfillRandomnessfulfillRandomness期望

  function fulfillRandomness(bytes32 requestId, uint256 randomness) 

I am not sure if this is the correct way of calling fulfillRandomness我不确定这是否是调用fulfillRandomness的正确方法

function generateRandomNumber(address _random) external(bytes32 requestId) {
        randomness_interface(_random).fulfillRandomness(uint256);
    }

Because as far as I know, fulfillRandomness gets called by the chainlink node, so you make request, get the random number and then chainlink will call fulfillRandomness .因为据我所知, fulfillRandomness被chainlink 节点调用,所以你提出请求,获取随机数,然后chainlink 将调用fulfillRandomness I think you should have written like this:我认为你应该这样写:

function fulfillRandomness(bytes32 requestId,uint256 randomNumber) internal override{

}

暂无
暂无

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

相关问题 PHP接口。 不同的退货类型 - PHP interfaces. Different return type 尝试将Type强制转换为接口时,为什么会收到“ InvalidCastException:指定的强制转换无效”的信息 - Why am I getting an “InvalidCastException: Specified cast is not valid.” when trying to cast a Type to interface 期望接口时传递特定对象的列表。 怎么样? - Pass list of specific objects when expecting the interfaces. How? 使用接口。 如何验证我的 Java 接口? - Using interfaces. How can I verify my Java interface? Typescript 错误:将参数声明为接口的联合。 它不是选择一个选项,而是选择所有选项 - Typescript Error : Declaring a parameter as a union of interfaces. Instead of picking one of the choices, it picks all of them 对接口感到困惑。 如何在一个类中调用接口方法并在另一个类中定义接口方法? - Confused about Interfaces. How do I call an interface method in one class and define it in another? 使用外部模块时如何正确使用TypeScript接口? - How do I use TypeScript Interfaces correctly when using External Modules? 为什么在调用带有接口作为构造函数中的参数的类时出现“找不到源”错误? - Why am I getting a 'source not found' error when calling a class with an interface as the argument in the constructor? 使用接口创建类。 然后在代码隐藏中迭代它 - Create classes with interfaces. Then iterate though it in codebehind 当继承接口用于类型提示时,为什么 PHP 会发出兼容性错误? - Why does PHP emit compatibility error when inherited interfaces are used for type hinting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM