0

I want to be able to input 7 seconds or 300 days in a timelock smart contract after deploying the contract.

I don't want to hard code the time frame before deploying the contract.

Here's the code:

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

}

}

How do I input a parameter that will take both a uint and a string as one parameter?

1 Answer 1

1

Solidity is a statically typed language, and the type of each variable needs to be specified, so the type can't be dynamic.

block.timestamp is a uint value in seconds since unix epoch, so the type of the argument should be uint, otherwise the calculation block.timestamp + _time will fail

function(uint _time) public payable {
  balance[msg.sender] += msg.value;
  timelock[meg.sender] = block.timestamp + _time
}

In order to call this function successfully, any string value can be converted into uint256 value in ethers JS and input as argument in that function call

If you want to concatenate string and unit in solidity, you can reference this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.