encodePacked
Generates ABI non-standard packed encoded data given a set of solidity types compatible with packed encoding.
Import
ts
import { encodePacked } from 'viem'
Usage
ts
encodePacked(
['address', 'string', 'bytes16[]'],
[
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
'hello world',
['0xdeadbeefdeadbeefdeadbeefdeadbeef', '0xcafebabecafebabecafebabecafebabe']
]
)
// 0xd8da6bf26964af9d7eed9e03e53415d37aa9604568656c6c6f20776f726c64deadbeefdeadbeefdeadbeefdeadbeef00000000000000000000000000000000cafebabecafebabecafebabecafebabe00000000000000000000000000000000
Returns
The encoded packed data.
Parameters
types
- Type:
PackedAbiType[]
Set of ABI types to pack encode.
ts
encodePacked(
['address', 'string', 'bytes16[]'],
[
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
'hello world',
['0xdeadbeefdeadbeefdeadbeefdeadbeef', '0xcafebabecafebabecafebabecafebabe']
]
)
values
The set of primitive values that correspond to the ABI types defined in types
.
ts
encodePacked(
['address', 'string', 'bytes16[]'],
[
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
'hello world',
['0xdeadbeefdeadbeefdeadbeefdeadbeef', '0xcafebabecafebabecafebabecafebabe']
]
)