Fund orders
An order is funded by its steps. summary.actionNeeded says what to ask of the user now:
"actionNeeded": { "kind": "send_transaction", "executor": { "chain": "eip155:42161", "address": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4" }, "steps": ["approve", "deposit"]}kindissend_transaction, where theexecutorsends EVM contract calls, orsend_transfer, where anyone sends one token transfer.stepslists the ids of the steps to run, in order. A step’sidsays what it does:approve_reset,approve,depositortransfer.actionNeededis null once the deposit shows or the order publishes, and once funding closes atfundBy.
The deposit must be exactly the quoted amount, terms.send, sent before terms.fundBy. Each step’s instruction says how. Don’t guess at a step whose instruction.format you don’t know. It can’t be run.
The source chain decides how the order is funded:
- On an EVM source, the
payersends contract calls: any approvals, then the deposit. - On a non-EVM source, anyone sends one token transfer to a deposit address. Non-EVM chains accept nothing else.
EVM source: send the contract calls
Section titled “EVM source: send the contract calls”On an EVM source the steps are transaction steps for the payer to send, one after another and in this order:
approve_reset, when a leftover allowance must be cleared first,approve, when the allowance is short,deposit.
Each step’s instruction (format evm_call) holds the transaction in payload:
{ "id": "deposit", "type": "transaction", "status": "pending", "chain": "eip155:42161", "actor": "payer", "executor": { "chain": "eip155:42161", "address": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4" }, "instruction": { "format": "evm_call", "payload": { "chainId": 42161, "from": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4", "to": "0x1111111111111111111111111111111111111111", "data": "0xf3125a1f…", "value": "100000000000000", "gasLimit": "250000" }, "approval": null, "allowance": { "spender": "0x1111111111111111111111111111111111111111", "amount": { "asset": { "id": "eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "chain": "eip155:42161", "symbol": "USDC", "decimals": 6 }, "amount": "100000000" } } }}The rules for the wallet:
- Send each transaction from
payload.from, the payer, onpayload.chainId. A deposit from any other account can’t fund the order: to get it back, contact Khalani with the transaction hash. Check the wallet’s connected account before you send. - Send
valueandgasLimitas given. Both are decimal strings:valuein wei,gasLimitin gas units. The deposit’svalueis the relay fee when the order was created, plus the amount for a native coin. If the fee rises before the deposit lands, the deposit reverts, and you need a new quote and a new order. - Wait for each transaction to succeed before you send the next. A receipt alone doesn’t rule out a revert, so check its status.
- Send the deposit once. A second deposit can’t fund anything, and getting it back means contacting Khalani with its transaction hash. For a native coin, no allowance stops a second one from landing.
An approval step’s instruction.approval names the spender and the amount it approves. The deposit’s instruction.allowance names the allowance it needs. A native coin needs no approvals: its deposit is the only step, and its instruction.allowance is null, so skip the check below.
Check the allowance first
Section titled “Check the allowance first”The approval steps reflect the payer’s allowance when the order was created. Another order on the same token can change it since. So before the approvals, and again if the deposit reverts, read the payer’s allowance of the token in allowance.amount.asset for allowance.spender, and go by it:
| Allowance now | Send |
|---|---|
At least allowance.amount.amount |
Only the deposit. |
| 0 | approve(spender, allowance.amount.amount), then the deposit. |
| Anything between | approve(spender, 0), then approve(spender, allowance.amount.amount), then the deposit. Some tokens, such as USDT on Ethereum, revert an approval from one nonzero allowance to another. |
The approve_reset and approve steps are those approvals as the allowance stood at creation. Send them as given when the allowance hasn’t changed since. When it has, send your own approve calls on the token in allowance.amount.asset, and let the wallet estimate their gas. The quickstart does this with viem, sending only its own approvals.
With an EIP-1193 wallet, forward the payload’s fields, converting the decimal strings to hex:
const { from, to, data, value, gasLimit } = step.instruction.payload;await provider.request({ method: "eth_sendTransaction", params: [{ from, to, data, value: `0x${BigInt(value).toString(16)}`, gas: `0x${BigInt(gasLimit).toString(16)}` }],});Non-EVM source: send the transfer
Section titled “Non-EVM source: send the transfer”On a non-EVM source there is one transfer step, and anyone may send it, including an exchange withdrawal that can follow every instruction returned. Its instruction (format transfer) names the deposit address and the amount:
{ "format": "transfer", "to": { "chain": "<source chain>", "address": "<deposit address>" }, "amount": { "asset": { "id": "<asset id>", "chain": "<source chain>", "symbol": "USDT", "decimals": 6 }, "amount": "100000000" }}- Send exactly
amountof the asset toto, as given. Includememounchanged when the instruction supplies one; otherwise use no memo. A transfer of any other amount can’t fund the order, and Khalani returns it to the sender. - Send it once. To get a second transfer back, contact Khalani with its transaction hash.
- Check the option’s
requiresfirst. Some chains ask more of the paying wallet. See Notes for specific chains. - A transfer that can’t fund the order closes the step and adds the
NOT_PUBLISHEDnotice tosummary.notices. Don’t send another. Khalani returns it.
How the steps progress
Section titled “How the steps progress”Step status |
Meaning |
|---|---|
pending |
Not seen yet. Run it if summary.actionNeeded lists it. |
completed |
The deposit showed, or the order published. |
closed |
Funding closed at fundBy, or a transfer couldn’t fund the order (NOT_PUBLISHED). Stop asking the user to pay. |
The steps stay pending until the order shows the deposit or publishes. Then every step completes together. This can take a few minutes after the transaction confirms, depending on the source chain.
The API doesn’t see your transactions before that. A step can still be listed after its transaction succeeds. Watch the transactions yourself, and send a step again only if its transaction failed.
Deadlines
Section titled “Deadlines”Send the deposit before terms.fundBy. At fundBy, funding closes on an order whose deposit hasn’t shown. Its steps show closed and actionNeeded turns null. A deposit sent in time can still show after that, and counts. Don’t let the user pay after fundBy: see Order lifecycle for what happens to a late deposit.
Track the order until summary.pollAfterSeconds is null.