Documentation/Build on Signet/To Ethereum
Off-chain Orders in TypeScript
Create Signet Orders in TypeScript
This page will walk you through creating and submitting off-chain Orders using TypeScript and the Signet SDK.
The Orders contract enables trustless, cross-chain asset swaps between Signet and Ethereum. Signet nodes listen for Order and Filled events, and ensure that all transactions that emit Orders have corresponding Fills executed on the destination chain in the same block.
Order events are emitted on Signet, while Filled events may be emitted on either Ethereum or Signet. Off-chain orders are pre-signed, using Permit2, and may be executed by a third-party filler, allowing users to perform gasless swaps.
Setup
Install the required packages:
pnpm add @signet-sh/sdk viemEnsure your account has approved Permit2 to spend your input tokens.
Consult the Parmigiana Quickstart guide for contract addresses and RPC endpoints.
Creating an Order
The SDK provides a simple order builder via the UnsignedOrder class. We can
start by creating a simple order that swaps 1 WETH on Signet for 1 WETH on
Ethereum:
import { createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import {
UnsignedOrder,
PARMIGIANA,
getTokenAddress,
parmigianaRollup,
} from "@signet-sh/sdk";
const account = privateKeyToAccount("0x...");
const client = createWalletClient({
account,
chain: parmigianaRollup,
transport: http("https://rpc.parmigiana.init4.tech"),
});
// Get token addresses for Parmigiana network
const rollupWeth = getTokenAddress("WETH", PARMIGIANA.rollupChainId, PARMIGIANA)!;
const hostWeth = getTokenAddress("WETH", PARMIGIANA.hostChainId, PARMIGIANA)!;
const signedOrder = await UnsignedOrder.new()
.withInput(rollupWeth, parseEther("1"))
.withOutput(
hostWeth,
parseEther("1"),
account.address,
Number(PARMIGIANA.hostChainId)
)
.withDeadline(BigInt(Math.floor(Date.now() / 1000) + 3600))
.withChain({
chainId: PARMIGIANA.rollupChainId,
orderContract: PARMIGIANA.rollupOrders,
})
.sign(client);The UnsignedOrder class provides methods for adding multiple inputs and
outputs, setting custom nonces, and more. See the
@signet-sh/sdk documentation
for the full API.
Submitting an Order
Once signed, the order can be submitted to the Signet network via the Signet tx cache. The tx cache makes the Order available to Searchers, who will include it in execution bundles.
import { createTxCacheClient, PARMIGIANA } from "@signet-sh/sdk";
const txCache = createTxCacheClient(PARMIGIANA.txCacheUrl);
const { id } = await txCache.submitOrder(signedOrder);
console.log(`Order submitted with ID: ${id}`);For on-chain order creation, check out Solidity Orders.