我希望能够输入7秒或300天,在一个时间锁智能合同部署后。
在部署合同之前,我不想硬编码时间框架。
下面是代码:
contract Timelock {
mapping(address => uint) balance;
mapping(address => uint) timelock;
function(uint string _time //not working) public payable {
balance[msg.sender] += msg.value;
timelock[meg.sender] = block.timestamp + _time
}
}如何输入同时使用uint和字符串作为参数的参数?
发布于 2022-11-29 22:09:19
Solidity是一种静态类型化语言,每个变量的类型都需要指定,所以类型不能是动态的。
block.timestamp是自unix时代以来的uint值,因此参数的类型应该是uint,否则计算block.timestamp + _time将失败。
function(uint _time) public payable {
balance[msg.sender] += msg.value;
timelock[meg.sender] = block.timestamp + _time
}为了成功地调用此函数,可以将任何string值转换为ethers中的uint256值,并在该函数调用中作为参数输入。
如果要将string和unit连接在一起,可以引用这。
https://ethereum.stackexchange.com/questions/140232
复制相似问题