As reported in this thread: https://github.com/ethereum/solidity/issues/3955
The new abi.encode*() methods offer a replacement to perform packing, which then can be passed to all these hashing functions.
Bottom line: As @mirg commented, just use abi.encodePacked() inside keccak256(). That is:
keccak256(abi.encodePacked(msg.sender, _unixTimestamp, _timeExpired))
actually in solidity docs it's pointing that for each public member variable there will be a getter is defined automatically.
In short you'll be able to get basic type public member like this: let x = await contract.totalAllocPoint();
you've been missing parenthesis here.
While you can get array like: let y = await contract.poolInfo(2);
if the array length is more than 3 in this case of course.
For mapping types
mapping (address => mapping(uint256 => Order)) public orderByAssetId;
await contract.orderByAssetId(address, id);
To explain it more, if you look into ABI generated from compiling your solidity contract you should be able to see like this:
Defined contract in solidity
contract MasterChef {
...
uint256 public totalAllocPoint = 0;
...
}
equals to ABI
{
"inputs": [],
"name": "totalAllocPoint",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
Keep on coding !
With Human-Readable ABI of ethers.js
const contract = new ethers.Contract(contractAddress, [
'function totalAllocPoint() public view returns (uint256)'
], provider)
await contract.totalAllocPoint()
Best Answer
Let's look at the function definition for
keccak256
:The input is not a string - it's a
BytesLike
type.With that in mind, here's how to rewrite the script to make it work:
The trick is to import another package from the ethers stack (
@ethersproject/strings
) that exports a function calledtoUtf8Bytes
, which converts your string toBytesLike
.