sway
sway copied to clipboard
Expose function selector from `ABI`
Labels may need to be adjusted...
I would like to be able to fetch the encoded value for any function on the ABI / interface.
Say I have the following ABI:
abi Vault {
pub fn withdraw(asset: AssetId, amount: u64);
}
If I want to make a low level call I need the function selector, which needs to be calculated. It would be useful if I could do
// Haven't considered the return type exactly but perhaps `Bytes` or something that can be converted to it
let selector = Vault.withdraw.function_selector;
I believe this would be equivalent to
// I think you're meant to take first 8 bytes from
let selector: b256 = sha256("withdraw(AssetId,u64)");