For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickstart: TypeScript + WASM

Sign and send your first Lighter order from TypeScript using the official WASM signer from lighter-go. Works in Node.js and the browser.

Lighter transactions are signed with a custom scheme (not EIP-712). The reference signer is written in Go and compiled to WebAssembly, so you can use it from any JavaScript runtime.

By the end of this page you will have one runnable script that verifies your API key, places a limit order on mainnet from Node.js and cancels it. Using Python instead? See Get Started.

Prerequisites

1. Build the signer

git clone https://github.com/elliottech/lighter-go
cd lighter-go
GOOS=js GOARCH=wasm go build -trimpath -o ./build/lighter-signer.wasm ./wasm/

# Go's JS glue file, from your Go install
SRC="$(go env GOROOT)/lib/wasm/wasm_exec.js"
[ -f "$SRC" ] || SRC="$(go env GOROOT)/misc/wasm/wasm_exec.js"
cp "$SRC" ./build/wasm_exec.js

Build both files together

wasm_exec.js must come from the same Go version that built the .wasm. Rebuild both together.

2. Set up the project

3. The script

Save as quickstart.ts. It verifies your API key, places a buy order far below the market (so it won't fill), then cancels it.

Notes on what it does:

  • Keep the WASM signer off the network. CreateClient gets an empty URL and every request goes through JS fetch. Avoid CheckClient and nonce = -1 (which asks the signer to fetch the nonce itself): both use Go's HTTP stack, which can't reach the network from WASM (you'll see dial tcp: lookup …).

  • Key check: an auth token signed by your key is only accepted if that key is registered for the account. Any non-200 code (e.g. invalid signature, couldnt find account) means the key, key index or account index is wrong.

  • Integers: prices and sizes are integers scaled by the market's price_decimals / size_decimals from orderBookDetails. See Core concepts.

  • Every function returns an object; if it has an error field, the call failed. check() turns that into an exception.

4. Run it

Expected output:

Reusing the signer in your app

The guides import the loader from a small module. Split it out of the script like this:

Running in the browser

Same code, but load the module with fetch:

Serve the .wasm with Content-Type: application/wasm. Pre-compressing with Brotli/Gzip is recommended. The same rules apply as in Node: pass an empty URL to CreateClient and make HTTP calls with fetch.

Next steps

Last updated

Was this helpful?