NEAR Intents: Intents SDK
Complete library to interact with NEAR Intents
The NEAR Intents SDK provides tools for intent execution, deposits, withdrawals, and interacting with various bridge implementations across multiple blockchains.
For a higher-level API focused on cross-chain swaps, check out the 1Click Swap API and its SDK libraries for TypeScript, Go, and Rust.
Feature Status
Feature Status Description Intent Execution ✅ Sign, submit, and track intent execution on NEAR Intents Deposits ❌ Deposit funds to NEAR Intents (use bridge interfaces directly) Withdrawals ✅ Complete withdrawal functionality from NEAR Intents to external chains
[!WARNING]
The Intents SDK provides low-level functionality for interacting with NEAR Intents, check out the 1Click Swap API for a higher-level API focused on cross-chain swaps
Using the SDK
1. Install the SDK
npm install @defuse-protocol/intents-sdk --save-exact
2. Initialize the SDK
import { IntentsSDK, createIntentSignerNearKeyPair } from '@defuse-protocol/intents-sdk';
import { KeyPair } from 'near-api-js';
const sdk = new IntentsSDK({
referral: 'your-referral-code',
intentSigner: createIntentSignerNearKeyPair({
signer: KeyPair.fromString('your-private-key'),
accountId: 'your-account.near',
}),
});
3. Process a withdrawal
The most common use case — withdraw funds from NEAR Intents to an external chain:
const result = await sdk.processWithdrawal({
withdrawalParams: {
assetId: 'nep141:usdt.tether-token.near',
amount: 1000000n, // 1 USDT (6 decimals)
destinationAddress: '0x742d35Cc6634C0532925a3b8D84B2021F90a51A3',
feeInclusive: false,
},
});
console.log('Intent hash:', result.intentHash);
console.log('Destination tx:', result.destinationTx);
4. Or execute a custom intent
For advanced use cases beyond withdrawals, use the lower-level signAndSendIntent method:
const result = await sdk.signAndSendIntent({
intents: [
{
intent: 'transfer',
receiver_id: 'recipient.near',
tokens: { 'usdt.tether-token.near': '1000000' },
},
],
});
console.log('Intent hash:', result.intentHash);
[!TIP]
Use
processWithdrawalfor withdrawals andsignAndSendIntentfor custom intent logic. The withdrawal method handles fee estimation, validation, and completion tracking automatically.
Next steps
Explore the Github Repository for the Intents SDK to learn about asset identifiers, intent signers, withdrawals, withdrawal routes, and intent management.