Skip to main content
A program takes its inputs as main’s typed parameters. The compiled bytecode holds no values for them: each cook appends the encoded arguments to the bytecode, and that whole payload is the program argument of Pot.cook(engine, program). One compiled program serves every set of values.
There is no function selector: the program reads its arguments from the bytes after its own code. The encoding is ABI-v1, the only one: a compiled program’s entryEncoding is always "abi-v1". To fix the values in the bytecode instead, pass args when compiling; see Bind arguments at compile time.

routes.encodeEntryArguments

Checks values against main’s declared parameters, in order, and encodes them in the layout main reads.

Import

Usage

entry-args.ts
The payload is the 223-byte program followed by its 64 bytes of arguments. Cook transactions sends it.

Signature

Parameters

A value takes the form of its parameter’s type:

Returns

Uint8Array: the encoded arguments, to append to the program’s bytecode.

Throws

A wrong number of values throws a RangeError; a value that is not of its parameter’s type throws a TypeError naming the parameter:
entry-args-error.ts

routes.decodeEntryArguments

The strict inverse of encodeEntryArguments: reads main’s arguments back from the bytes appended to the program.

Import

Usage

entry-args.ts above decodes the arguments it encoded:

Signature

Parameters

Returns

EntryValue[]: one value per declared parameter. Integers come back as bigint, an Int256 with its sign, addresses as hex, records as objects naming their fields.

Throws

A RangeError when encoded is not exactly the encoding encodeEntryArguments produces for the values it decodes to: truncated, padded or otherwise non-canonical bytes. The last line of the entry-args-error.ts output above is one.

Signed integers

An Int256 parameter is signed. Its word is the two’s complement of the value, and it decodes with its sign:
int256-args.ts
-10n is accepted for the Int256 parameter and refused for the Uint256 one. A value outside -2^255 through 2^255 - 1 throws a TypeError naming the parameter.

ABI-v1 layout

ABI-v1 is abi.encode of main’s parameters, with no selector:
entry-args-abi.ts
A record parameter of fixed size is the exception. main reads each parameter from one 32-byte head word, so such a record sits behind an offset word, as a dynamic parameter would. abi.encode writes its fields inline. The raw compiler marks it indirect in entryParams:
entry-args-tuple.ts
encodeEntryArguments starts with the offset word 0x40; encodeAbiParameters starts with the field amount. A program given the inline layout reverts with no data: on a local fork of Base at block 52992458 with the current contracts, this program’s cook returned 7 with encodeEntryArguments’s bytes and reverted with encodeAbiParameters’s. Encode a program with an indirect parameter with routes.encodeEntryArguments.

Raw compiler arguments

A program from the raw compile() carries entryParams, its parameters as an ABI parameter list. When no parameter is indirect, viem’s encodeAbiParameters(entryParams, values) is the argument payload as it stands:
raw-entry-params.ts
Check for indirect before you encode with viem, as the example does. A parameter bound with the raw args option is not in entryParams, so it takes no value. On Solana, Account parameters are not in entryParams either: they are attached accounts, which the manifest lists.

Next steps