Package Exports
- @avail-project/nexus-core
Readme
@avail-project/nexus/core
A headless TypeScript SDK for cross-chain operations, token bridging, swapping, and unified balance management β built for backends, CLIs, and custom UI integrations.
β‘ Powering next-generation cross-chain apps with a single interface.
π¦ Installation
npm install @avail-project/nexus-coreπ Quick Start
import { NexusSDK, NEXUS_EVENTS } from '@avail-project/nexus-core';
// Initialize SDK
const sdk = new NexusSDK({ network: 'mainnet' });
await sdk.initialize(provider); // Your EVM-compatible wallet provider
// (Optional) Add TRON support
const tronLinkAdapter = new TronLinkAdapter();
sdk.addTron(tronLinkAdapter);
// ---------------------------
// 1οΈβ£ Get unified balances
// ---------------------------
const balances = await sdk.getUnifiedBalances(false); // false = CA balances only
console.log('Balances:', balances);
// ---------------------------
// 2οΈβ£ Bridge tokens
// ---------------------------
const bridgeResult = await sdk.bridge(
{
token: 'USDC',
amount: 1_500_000n,
recipient: '0x...' // Optional
chainId: 137, // Polygon
},
{
onEvent: (event) => {
if (event.name === NEXUS_EVENTS.STEPS_LIST) console.log('Bridge steps:', event.args);
if (event.name === NEXUS_EVENTS.STEP_COMPLETE) console.log('Step completed:', event.args);
},
},
);
// ---------------------------
// 3οΈβ£ Transfer tokens
// ---------------------------
const transferResult = await sdk.bridgeAndTransfer(
{
token: 'ETH',
amount: 1_500_000n,
chainId: 1, // Ethereum
recipient: '0x742d35Cc6634C0532925a3b8D4C9db96c4b4Db45',
},
{
onEvent: (event) => {
if (event.name === NEXUS_EVENTS.STEPS_LIST) console.log('Transfer steps:', event.args);
if (event.name === NEXUS_EVENTS.STEP_COMPLETE) console.log('Step completed:', event.args);
},
},
);
// ---------------------------
// 4οΈβ£ Execute a contract
// ---------------------------
const executeResult = await sdk.execute(
{
to: '0x...',
value: 0n,
data: '0x...',
tokenApproval: { token: 'USDC', amount: 10000n },
},
{
onEvent: (event) => {
if (event.name === NEXUS_EVENTS.STEPS_LIST) console.log('Execute steps:', event.args);
if (event.name === NEXUS_EVENTS.STEP_COMPLETE) console.log('Step completed:', event.args);
},
},
);
// ---------------------------
// 5οΈβ£ Bridge and Execute
// ---------------------------
const bridgeAndExecuteResult = await sdk.bridgeAndExecute(
{
token: 'USDC',
amount: 100_000_000n,
toChainId: 1,
sourceChains: [8453],
execute: {
to: '0x...',
data: '0x...',
tokenApproval: { token: 'USDC', amount: 100_000_000n },
},
},
{
onEvent: (event) => {
if (event.name === NEXUS_EVENTS.STEPS_LIST) console.log('Bridge+Execute steps:', event.args);
if (event.name === NEXUS_EVENTS.STEP_COMPLETE) console.log('Step completed:', event.args);
},
},
);
// ---------------------------
// 6οΈβ£ Swap tokens
// ---------------------------
const swapResult = await sdk.swapWithExactIn(
{
from: [
{ chainId: 10, amount: 1_000_000n, tokenAddress: '0x...' },
],
toChainId: 8453,
toTokenAddress: '0x...',
},
{
onEvent: (event) => console.log('Swap event:', event),
},
);
β¨ Core Features
- Cross-chain bridging β Move tokens seamlessly across 16+ chains.
- Cross-chain swaps β Execute EXACT_IN and EXACT_OUT swaps between any supported networks.
- Unified balances β Aggregate user assets and balances across all connected chains.
- Optimized transfers β Automatically choose the most efficient transfer route.
- Contract execution β Call smart contracts with automatic bridging and funding logic.
- Transaction simulation β Estimate gas, fees, and required approvals before sending.
- Complete testnet coverage β Full multi-chain test environment.
- Comprehensive utilities β Address, token, and chain helpers built in.
π§ Smart Optimizations
π Bridge Skip Optimization
During bridge-and-execute operations, the SDK checks whether sufficient funds already exist on the destination chain:
- Balance detection β Verifies token and gas availability.
- Integrated gas supply β Provides gas alongside bridged tokens.
- Adaptive bridging β Skips unnecessary bridging or transfers only the shortfall.
- Seamless fallback β Uses chain abstraction if local funds are insufficient.
β‘ Direct Transfer Optimization
For transfers, the SDK automatically chooses the most efficient execution path:
- Local balance checking β Confirms token and gas availability on the target chain.
- Direct EVM transfers β Uses native transfers where possible (faster, cheaper).
- Chain abstraction fallback β Uses CA routing only when required.
- Universal compatibility β Works with both native tokens (ETH, MATIC) and ERC-20s (USDC, USDT).
ποΈ Initialization
import { NexusSDK, type NexusNetwork } from '@avail-project/nexus-core';
// Mainnet
const sdk = new NexusSDK({ network: 'mainnet' });
// Testnet
const sdkTest = new NexusSDK({ network: 'testnet' });
// Initialize with wallet provider
await sdk.initialize(window.ethereum);π‘ Event Handling
All main SDK functions support the onEvent hook:
bridgebridgeAndTransferexecutebridgeAndExecuteswapWithExactIn/swapWithExactOut
Example usage for progress steps:
sdk.bridge({...}, {
onEvent: (event) => {
if(event.name === NEXUS_EVENTS.STEPS_LIST) {
// Store list of steps
} else if(event.name === NEXUS_EVENTS.STEP_COMPLETE) {
// Mark step as done
}
}
});Additional hooks for user interactions:
sdk.setOnIntentHook(({ intent, allow, deny, refresh }) => {
if (userApproves) allow();
else deny();
});
sdk.setOnSwapIntentHook(({ intent, allow, deny, refresh }) => {
if (userApproves) allow();
else deny();
});
sdk.setOnAllowanceHook(({ sources, allow, deny }) => {
allow(['min']); // 'max' or custom bigint[] supported
});Consistent Event Pattern
| Operation Type | Event Name | Description |
|---|---|---|
| Bridge / Execute | STEPS_LIST |
Full ordered list of steps emitted once |
STEP_COMPLETE |
Fired per completed step with data | |
| Swap | SWAP_STEP_COMPLETE |
Fired per completed step with data |
All events include typeID, transactionHash, explorerURL, and error (if any).
π° Balance Operations
const balances = await sdk.getUnifiedBalances(); // CA balances
const allBalances = await sdk.getUnifiedBalances(true); // Includes swappable tokensπ Bridge Operations
const result = await sdk.bridge({ token: 'USDC', amount: 83_500_000n, chainId: 137 });
const simulation = await sdk.simulateBridge({ token: 'USDC', amount: 83_500_000n, chainId: 137 });π Transfer Operations
const result = await sdk.bridgeAndTransfer({
token: 'USDC',
amount: 1_530_000n,
chainId: 42161,
recipient: '0x...',
});
const simulation = await sdk.simulateBridgeAndTransfer({
token: 'USDC',
amount: 1_530_000n, // = 1.53 USDC
chainId: 42161,
recipient: '0x...',
});βοΈ Execute & Bridge+Execute
// Direct contract execution
const result = await sdk.execute({
toChainId: 1,
to: '0xc3d688B66703497DAA19211EEdff47f25384cdc3',
data: '0x...',
tokenApproval: { token: 'USDC', amount: 1000000n },
});
// Bridge and execute
const result2 = await sdk.bridgeAndExecute({
token: 'USDC',
amount: 100_000_000n,
toChainId: 1,
sourceChains: [8453],
execute: {
to: '0xa354F35829Ae975e850e23e9615b11Da1B3dC4DE',
data: '0x...',
tokenApproval: { token: 'USDC', amount: 100_000_000n },
},
});π Swap Operations
const swapResult = await sdk.swapWithExactIn(
{
from: [{ chainId: 10, amount: 1_000_000n, tokenAddress: '0x...' }],
toChainId: 8453,
toTokenAddress: '0x...',
},
{ onEvent: (event) => console.log(event) },
);Swap Types
| Type | Description | Example |
|---|---|---|
| EXACT_IN | Specify the amount youβre spending; output varies | βSwap 100 USDC for max ETHβ |
| EXACT_OUT | Specify the amount youβll receive; input varies | βGet exactly 1 ETHβ |
π§© Intent Management
const intents = await sdk.getMyIntents(1);
console.log('Active intents:', intents);π οΈ Utilities
const isValid = sdk.utils.isValidAddress('0x...');
const chainMeta = sdk.utils.getChainMetadata(137);
const formatted = sdk.utils.formatTokenAmount('1000000', 'USDC'); // "1.0 USDC"π§Ύ Error Handling
try {
await sdk.bridge({ token: 'USDC', amount: 1.53, chainId: 137 });
} catch (err) {
if (err instanceof NexusError) {
console.error(`[${err.code}] ${err.message}`);
} else {
console.error('Unexpected error:', err);
}
}π§ TypeScript Support
import type {
BridgeParams,
ExecuteParams,
TransferParams,
SwapResult,
NexusNetwork,
TokenMetadata,
} from '@avail-project/nexus-core';π Supported Networks
Mainnets
| Network | Chain ID | Native | Status |
|---|---|---|---|
| Ethereum | 1 | ETH | β |
| Optimism | 10 | ETH | β |
| Polygon | 137 | MATIC | β |
| Arbitrum | 42161 | ETH | β |
| Avalanche | 43114 | AVAX | β |
| Base | 8453 | ETH | β |
| Scroll | 534352 | ETH | β |
| Sophon | 50104 | SOPH | β |
| Kaia | 8217 | KAIA | β |
| BNB | 56 | BNB | β |
| HyperEVM | 999 | HYPE | β |
| TRON | 728126428 | TRX | β |
Testnets
| Network | Chain ID | Native | Status |
|---|---|---|---|
| Optimism Sepolia | 11155420 | ETH | β |
| Polygon Amoy | 80002 | MATIC | β |
| Arbitrum Sepolia | 421614 | ETH | β |
| Base Sepolia | 84532 | ETH | β |
| Sepolia | 11155111 | ETH | β |
| Monad Testnet | 10143 | MON | β |
| Validium | 567 | VLDM | β |
π Supported Tokens
| Token | Name | Decimals | Availability |
|---|---|---|---|
| ETH | Ethereum | 18 | All EVM chains |
| USDC | USD Coin | 6 | All supported |
| USDT | Tether USD | 6 | All supported |
π Resources
- GitHub: availproject/nexus-sdk
- Docs: docs.availproject.org