Skip to main content

NitroliteClient

The NitroliteClient class is the main entry point for interacting with Nitrolite state channels. It provides a comprehensive set of methods for managing channels, deposits, and funds.

Quick Start

import { NitroliteClient } from '@erc7824/nitrolite';

// Initialize client
const nitroliteClient = new NitroliteClient({
publicClient,
walletClient,
addresses: {
custody: '0x...',
adjudicator: '0x...',
guestAddress: '0x...',
tokenAddress: '0x...'
},
chainId: 137, // Polygon mainnet
challengeDuration: 100n
});

// 1. Deposit funds
const depositTxHash = await nitroliteClient.deposit(1000000n);

// 2. Create a channel
const { channelId, initialState, txHash } = await nitroliteClient.createChannel({
initialAllocationAmounts: [700000n, 300000n],
stateData: '0x1234'
});

// 3. Resize the channel when needed
const resizeTxHash = await nitroliteClient.resizeChannel({
resizeState: {
channelId,
stateData: '0x5678',
allocations: newAllocations,
version: 2n,
intent: StateIntent.RESIZE,
serverSignature: signature
},
proofStates: []
});

// 4. Close the channel
const closeTxHash = await nitroliteClient.closeChannel({
finalState: {
channelId,
stateData: '0x5678',
allocations: newAllocations,
version: 5n,
serverSignature: signature
}
});

// 5. Withdraw funds
const withdrawTxHash = await nitroliteClient.withdrawal(800000n);