Is there any suggested implementation to calculate Solidity functions signatures from their ABI using only ethers?
e.g. web3: https://ethereum.stackexchange.com/a/78316
Try this?
const abi = ["function transfer(address,uint256)"];
const iface = new ethers.utils.Interface(abi);
console.log('sighash', iface.getSighash("transfer"));
From doc: interface.getSighash
Did you want the sighash (also called the selector) or the Solidity source code version of the method?
If you have a contract, you can use contract.interface.getFragment("transfer").format() to get the minimal solidity source. There are multiple formats a available.
If you are looking for the selector (the 4 byte prefix for the data), the answer by @yuetloo is what you are looking for (if you already have a contract object, its interface is available via contract.interface) :)
Did you want the sighash (also called the selector) or the Solidity source code version of the method?
If you have a contract, you can use
contract.interface.getFragment("transfer").format()to get the minimal solidity source. There are multiple formats a available.If you are looking for the selector (the 4 byte prefix for the data), the answer by @yuetloo is what you are looking for (if you already have a contract object, its interface is available via
contract.interface) :)
Yes, it was just the selectors in my case, but thank you for the interesting ethers v5 API about Function Fragments
I had to calculate the methods selectors out of this object in Hardhat: https://github.com/wighawag/hardhat-deploy/blob/a842674b5a5a47ad2ee5b91c2fae1d3e1840e9b6/types.ts#L282
Most helpful comment
Try this?
From doc: interface.getSighash