[英]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).fulfillRandomness
和fulfillRandomness
期望
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.