Skip to content
Guides

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"]
}
  • kind is send_transaction, where the executor sends EVM contract calls, or send_transfer, where anyone sends one token transfer.
  • steps lists the ids of the steps to run, in order. A step’s id says what it does: approve_reset, approve, deposit or transfer.
  • actionNeeded is null once the deposit shows or the order publishes, and once funding closes at fundBy.

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 payer sends 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.

On an EVM source the steps are transaction steps for the payer to send, one after another and in this order:

  1. approve_reset, when a leftover allowance must be cleared first,
  2. approve, when the allowance is short,
  3. 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, on payload.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 value and gasLimit as given. Both are decimal strings: value in wei, gasLimit in gas units. The deposit’s value is 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.

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)}` }],
});

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 amount of the asset to to, as given. Include memo unchanged 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 requires first. 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_PUBLISHED notice to summary.notices. Don’t send another. Khalani returns it.
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.

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.