@tomo-inc/transaction-builder-sdk
v0.0.15
Published
Tomo Wallet Transaction Builder SDK is a comprehensive TypeScript library that provides developers with easy-to-use interfaces for integrating wallet functionalities, swap operations, and cross-chain transactions into their applications.
Readme
@tomo-inc/transaction-builder-sdk
Tomo Wallet Transaction Builder SDK is a comprehensive TypeScript library that provides developers with easy-to-use interfaces for integrating wallet functionalities, swap operations, and cross-chain transactions into their applications.
Features
- Multi-chain Support: Works with EVM, Solana, TRON, and other major blockchain platforms
- Swap Operations: Fetch quotes and build transactions for token swaps across DEXes
- Cross-chain Bridge: Support for cross-chain token transfers
- Token Approvals: Handle ERC20 token approvals and permit signatures
- Transaction Building: Generate ready-to-sign transactions for various operations
- Chain Information: Access detailed information about supported blockchain networks
Installation
npm install @tomo-inc/transaction-builder-sdkQuick Start
First, initialize the SDK with your API credentials:
import { Business } from "@tomo-inc/transaction-builder-sdk";
const business = new Business({
config: {
CLIENT_ID: "your-client-id",
},
tomoStage: "prod", // or 'dev' for development
});Chain Information
Get information about supported chains for different operations:
// Get all supported chains
const allChains = business.getChains();
// Get chains that support swap operations
const swapChains = business.getSwapSupportChains();
// Get chains that support bridge operations
const bridgeChains = business.getBridgeSupportChains();Swap Operations
Fetch quotes and build transactions for token swaps on the same chain:
// Get swap quotes
const quotes = await business.getSwapQuotes({
sender: "0x...", // User's wallet address
recipient: "0x...", // Recipient address (usually same as sender)
fromToken: {
address: "0x...", // Token contract address (use '' for native token)
chain: {
chainId: 1, // Ethereum mainnet
// ... other chain properties
},
},
toToken: {
address: "0x...", // Token contract address
chain: {
chainId: 1, // Must be same chain for swaps
// ... other chain properties
},
},
amount: "1000000000000000000", // Amount in token's smallest unit (e.g., wei for ETH)
slippage: 5, // 5% slippage tolerance
});
// Build swap transaction
const swapTx = await business.swapBuilder(quotes[0], {
// Same parameters as getSwapQuotes
});Cross-chain Bridge
Support for cross-chain token transfers:
// Get bridge quotes
const bridgeQuotes = await business.getBridgeQuotes({
sender: "0x...", // User's wallet address on source chain
recipient: "0x...", // Recipient address on destination chain
fromToken: {
address: "0x...", // Token contract address on source chain
chain: {
chainId: 1, // Source chain (e.g., Ethereum)
// ... other chain properties
},
},
toToken: {
address: "0x...", // Token contract address on destination chain
chain: {
chainId: 56, // Destination chain (e.g., BSC)
// ... other chain properties
},
},
amount: "1000000000000000000", // Amount in token's smallest unit
slippage: 5, // 5% slippage tolerance
});
// Build bridge transaction
const bridgeTx = await business.bridgeBuilder(bridgeQuotes[0], {
// Same parameters as getBridgeQuotes
});Token Approvals
Handle ERC20 token approvals and permit signatures:
import { useSignTypedData } from "wagmi";
const { signTypedDataAsync } = useSignTypedData();
// Build approval transaction (for tokens that don't support permit)
const approveTx = await business.getApproveBuilder(quote, quoteParams);
// For tokens that support permit signatures (EIP-712)
const permitTypeData = await business.evm.getPermitTypeData(quoteParams, quote);
// Sign the permit data with wallet
const signature = await signTypedDataAsync(permitTypeData);
// Use the signature when building the transaction
const swapTx = await business.swapBuilder(quote, quoteParams, {
signature,
permitTypeData,
});API Reference
Core Methods
- getSwapQuotes(params) - Fetch quotes for token swaps on the same chain
- getBridgeQuotes(params) - Fetch quotes for cross-chain transfers
- swapBuilder(quote, quoteParams, permitParams?) - Build swap transaction data
- bridgeBuilder(quote, quoteParams, permitParams?) - Build bridge transaction data
- getApproveBuilder(quote, quoteParams) - Build token approval transaction
EVM-specific Methods
- evm.getPermitTypeData(quoteParams, quote) - Generate EIP-712 typed data for permit signatures
Chain Functions
- getChains() - Returns all supported chains
- getSwapSupportChains() - Returns chains that support swap operations
- getBridgeSupportChains() - Returns chains that support bridge operations
License
MIT
