这是我的主要智能合同的代码。后两个函数的错误。
来自solidity的
:TypeError:函数调用中参数的无效类型。请求从类型( uint256 )到uint256的隐式转换无效。
-> contracts/DIV4.sol: 39 :57:而今:39-39\x{e 010} randomness_interface(_random).fulfillRandomness(uint256);
^
from : TypeError:函数调用中参数的无效类型。请求从类型( bytes32 )到bytes32的隐式转换无效。
-> contracts/DIV4.sol: 43 :55: /DIV4.sol
^
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文件
pragma solidity ^0.8.0;
interface randomness_interface {
function fulfillRandomness(uint256 randomness) external view returns (uint);
function getRandomNumber(bytes32 requestId) external;
}最后,文件与所有随机化发生。
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);
}
}发布于 2022-01-10 20:46:31
您没有将正确的参数传递给函数。
-
function generateRandomNumber(address _random) external(bytes32 requestId) {
randomness_interface(_random).fulfillRandomness(uint256);
}您正在调用randomness_interface(_random).fulfillRandomness和fulfillRandomness期望
function fulfillRandomness(bytes32 requestId, uint256 randomness) 我不确定这是否是调用fulfillRandomness的正确方式
function generateRandomNumber(address _random) external(bytes32 requestId) {
randomness_interface(_random).fulfillRandomness(uint256);
}因为据我所知,fulfillRandomness被链结调用,所以你提出请求,得到随机数,然后链结会调用fulfillRandomness。我觉得你应该这样写:
function fulfillRandomness(bytes32 requestId,uint256 randomNumber) internal override{
}https://stackoverflow.com/questions/70658482
复制相似问题