Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.unlink.xyz/llms.txt

Use this file to discover all available pages before exploring further.

Deposit ERC-20 tokens into the unlink contract. The deposit goes into the account bound to your unlink session (set via tenant.forUser({ account }), see Quickstart). Register the account once before depositing. depositWithApproval() is the recommended path: it runs the Permit2 approval (when needed), waits for confirmation, and then runs the deposit in one call. Use deposit() directly only when the token is already approved or when you want raw control over the approval flow.
const result = await unlink.depositWithApproval({
  token: "0xTokenAddress",
  amount: "1000000000000000000",
});

const confirmed = await unlink.pollTransactionStatus(result.txId);

Parameters (depositWithApproval)

ParameterTypeRequiredDescription
tokenstringYesERC-20 token address
amountstringYesAmount in wei
deadlinenumberNoPermit2 deadline (unix seconds). Defaults to 1 hour from now.
noncestringNoOverride Permit2 nonce (auto-managed by default)
evmEvmProviderNoOverride the EVM provider for this call
waitForApproval(txHash) => Promise<void>NoOverride the approval-confirmation wait (defaults to polling).
Returns: { txId: string; status: string }

Advanced: separate approval + deposit

If you’ve already arranged Permit2 approval out of band, or you want to integrate the approval into a custom receipt-polling pipeline, use the lower-level helpers:
const approval = await unlink.ensureErc20Approval({
  token: "0xTokenAddress",
  amount: "1000000000000000000",
});

if (approval.status === "submitted") {
  // Wait for tx to be mined before depositing
  console.log("Approval tx:", approval.txHash);
}
// If approval.status === "already-approved", no transaction was needed

const result = await unlink.deposit({
  token: "0xTokenAddress",
  amount: "1000000000000000000",
});

const confirmed = await unlink.pollTransactionStatus(result.txId);
You can also inspect approval state or build the approval transaction manually:
const state = await unlink.getApprovalState({ token, amount });
// state.isApproved: boolean

const tx = await unlink.buildApprovalTx({ token, amount });
// tx: { to: string; data: string; value?: bigint }
Approval methods require an EVM provider with getErc20Allowance. ensureErc20Approval and depositWithApproval also require sendTransaction.