The types to encode.
The values to encode. This array must have the same length as the types array.
Optional
packed: booleanWhether to use the non-standard packed mode. Defaults to
false
.
Optional
tight: booleanWhether to pack the values tightly. When enabled, the values
will be packed without any padding. This matches the behaviour of
ethereumjs-abi
. Defaults to false
.
Encode the data with the provided types. The types must be valid Solidity ABI types.
This will attempt to parse the values into the correct types. For example, if you pass in a hex string for a
uint256
, it will be parsed into abigint
. Regular strings are interpreted as UTF-8 strings. If you want to pass in a hex string, you must pass it in as aUint8Array
, or use the "0x"-prefix.It will also attempt to infer the types of the values. For example, if you pass in a string for a
uint256
, it will result in a TypeScript compile-time error. This does not work for all types, however. For example, if you use nested arrays or tuples, the type will be inferred asunknown
.The following types are supported:
address
: A 20-byte Ethereum address.Uint8Array
.bool
: A boolean value.true
orfalse
.bytes(n)
: A dynamic byte array.Uint8Array
.function
: A Solidity function.Uint8Array
.int(n)
: A signed integer.bigint
.string
: A dynamic UTF-8 string.Uint8Array
.tuple
: A tuple of values.uint(n)
: An unsigned integer.bigint
.Example
See
https://docs.soliditylang.org/en/v0.8.17/abi-spec.html
Returns
The ABI encoded bytes.