sauce compile compiles a SauceScript program for one chain and prints its bytecode.
Synopsis
Description
sauce compile reads one program file, or the program on stdin when the file is -, and compiles it as a standalone program for the chain --chain names. On that chain the program’s token symbols (USDC), protocol namespaces (UniswapV3.Factory), the chain id, the @sauce/token functions and the token writes (USDC.transfer, Token(address).approve) resolve without an import or an address. One file therefore compiles for every chain whose names it uses. A name the chain does not have is refused, naming the chain.
Relative imports are read from beside the file. A program read from stdin resolves them against the current directory, or the directory --source-dir names.
Without --chain, the chain comes from the file’s header: the // comment lines it starts with may hold // @chain <slug> and // @target <evm|svm>. --chain and --target take precedence over them, and a target that disagrees with the chain is an error. With neither a flag nor a header line, the command exits 2 and asks for --chain or a // @chain <slug> line. The other commands that compile a file read the same header.
An actions document compiles too: give its .json file in place of a .sauce.ts file.
--args and --args-json give main’s arguments. Each value is checked against its parameter’s type before anything is compiled, and the compile reports the payload size with the arguments appended. The arguments do not change the bytecode sauce compile prints: they are appended to it when a cook is built (sauce tx, sauce run).
Compiling works on every chain in the registry, preview chains included. It builds no transaction and signs nothing.
Options
Low-level options
--help lists these apart, with the note “a program’s inputs are main’s parameters, given with —args”.
A
--define the program never reads is named on stderr; it changes nothing.
Output
Without--json, stdout carries the bytecode as one 0x hex string. Notes go to stderr.
With --json, stdout carries one object:
Exit codes:
0 when the program compiles, 1 when it does not, 2 for a usage error such as a malformed argument.
Examples
Compile for Base
pay.sauce.ts
--chain ethereum, it differs only in the USDC address it embeds.
Report what the compile applied
Write the bytecode to a file
pay.arbitrum.hex. Arbitrum is a preview chain: the program compiles there, and sauce tx and sauce run refuse it.
Read a compile error
A program that usesto without declaring it:
1.
Read a rejected argument
2.
Next steps
sauce simulate: run the compiled program against a chain’s current state.sauce actions: compile a JSON actions document.- Names: how
USDCandUniswapV3.Factoryresolve on each chain. - Bytecode: what the compiled program is.
- Chains and endpoints:
--chain,--rpc-url,--configand preview chains.
