import { Abi } from '@tevm/voltaire';
// Define ABI
const transferAbi = {
type: 'function',
name: 'transfer',
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' }
],
outputs: [{ type: 'bool' }]
} as const;
// Encode function call
const fn = Abi.Function(transferAbi);
const encoded = fn.encodeParams([
'0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e',
1000000000000000000n
]);
// Returns Uint8Array with encoded parameters
// Get function selector
const selector = fn.getSelector();
// "0xa9059cbb"
// Decode function result
const resultData = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
const decoded = fn.decodeResult(resultData);
// [true]