Using SwapKit Toolboxes
SwapKit Toolboxes
Section titled “SwapKit Toolboxes”SwapKit toolboxes provide chain-specific utility functions for various blockchain networks. These toolboxes are used by wallet adapters and plugins, but can also be used directly for custom implementations.
Available Toolboxes
Section titled “Available Toolboxes”SwapKit provides specialized toolboxes for different blockchain ecosystems:
- EVM Toolbox: For Ethereum, BSC, Arbitrum, Avalanche, Polygon, etc.
- UTXO Toolbox: For Bitcoin, Litecoin, Dogecoin, etc.
- Cosmos Toolbox: For ATOM, THORChain, Kujira, etc.
- Solana Toolbox: For Solana blockchain
- Substrate Toolbox: For Polkadot, Chainflip, etc.
- Radix Toolbox: For Radix ecosystem
Each toolbox can be imported individually, which is preferred for frontend applications to minimize bundle size.
Importing Toolboxes
Section titled “Importing Toolboxes”You can initialize a toolbox either by importing specific toolbox methods like getEvmToolbox
or getUtxoToolbox
or by common toolbox method getToolbox
.
import { enum Chain
Chain } from "@swapkit/helpers";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox } from "@swapkit/toolboxes/evm";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
or
import { enum Chain
Chain } from "@swapkit/helpers";
import { function getToolbox<T extends Chain.Radix | Chain.Ripple | Chain.Solana | EVMChain | UTXOChain | CosmosChain | SubstrateChain>(chain: T, params?: ToolboxParams[T]): Promise<Toolboxes[T]>
getToolbox } from "@swapkit/toolboxes";
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams | undefined): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}
btcToolbox = await getToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: undefined): Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}>
getToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
EVM Toolbox
Section titled “EVM Toolbox”Importing and Initializing
Section titled “Importing and Initializing”import { enum Chain
Chain } from "@swapkit/helpers";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox, function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider } from "@swapkit/toolboxes/evm";
import { import ethers
ethers } from "ethers";
// Get a toolbox for a specific EVM chain
const const ethereumToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethereumToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const provider: ethers.JsonRpcProvider
provider = await function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
// With a signer (for transactions)
const const signer: ethers.Wallet
signer = new import ethers
ethers.new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected
to %%provider%%.Wallet("your-private-key-here", const provider: ethers.JsonRpcProvider
provider);
const const signingToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
signingToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, {
// You can provide a custom provider & signer
// provider: getProvider(Chain.Ethereum),
signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefined
signer,
});
Common Methods
Section titled “Common Methods”Address Validation
Section titled “Address Validation”import { enum Chain
Chain } from "@swapkit/helpers";
import { function evmValidateAddress({ address }: {
address: string;
}): boolean
evmValidateAddress } from "@swapkit/toolboxes/evm";
// Validate an Ethereum address | true or false
const const isValidAddress: boolean
isValidAddress = function evmValidateAddress({ address }: {
address: string;
}): boolean
evmValidateAddress({
address: string
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
});
Token Transfers
Section titled “Token Transfers”import { class AssetValue
AssetValue, enum Chain
Chain, enum FeeOption
FeeOption } from "@swapkit/helpers";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox, function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider } from "@swapkit/toolboxes/evm";
import { import ethers
ethers } from "ethers";
async function function transferTokens(): Promise<string>
transferTokens() {
// Create a signer
const const provider: ethers.JsonRpcProvider
provider = await function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const signer: ethers.Wallet
signer = new import ethers
ethers.new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected
to %%provider%%.Wallet("your-private-key", const provider: ethers.JsonRpcProvider
provider);
// Create a toolbox with signer
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<AssetValue>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, {
provider?: ethers.BrowserProvider | ethers.JsonRpcProvider | undefined
provider,
signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefined
signer
});
// ERC20 token transfer (USDC)
const const tokenAmount: AssetValue
tokenAmount = class AssetValue
AssetValue.AssetValue.from<{
chain: Chain.Ethereum;
symbol: string;
address: string;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
chain: Chain.Ethereum;
symbol: string;
address: string;
value: string;
} & AssetValueFromParams): AssetValue
from({
chain: Chain.Ethereum
chain: enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum,
symbol: string
symbol: "USDC",
address: string
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC contract
value: string
value: "10", // 10 USDC
});
// Transfer the tokens
const const txHash: string
txHash = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<AssetValue>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.transfer: ({ assetValue, memo, recipient, feeOptionKey, sender, ...tx }: EVMTransferParams) => Promise<string>
transfer({
assetValue: AssetValue
assetValue: const tokenAmount: AssetValue
tokenAmount,
recipient: string
recipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
from: const signer: ethers.Wallet
signer.BaseWallet.address: string
The wallet address.address, feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast,
});
return const txHash: string
txHash;
}
Smart Contract Interactions
Section titled “Smart Contract Interactions”import { enum Chain
Chain } from "@swapkit/helpers";
import { const erc20ABI: ({
inputs: never[];
stateMutability: string;
type: string;
anonymous?: undefined;
name?: undefined;
outputs?: undefined;
} | {
anonymous: boolean;
inputs: {
indexed: boolean;
internalType: string;
name: string;
type: string;
}[];
name: string;
type: string;
stateMutability?: undefined;
outputs?: undefined;
} | {
...;
})[]
erc20ABI } from "@swapkit/helpers/contracts";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox, function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider } from "@swapkit/toolboxes/evm";
import { import ethers
ethers } from "ethers";
async function function interactWithContract(): Promise<{
name: string;
balance: string;
transferTx: string;
}>
interactWithContract() {
// Create a signer
const const provider: ethers.JsonRpcProvider
provider = await function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>
getProvider(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const signer: ethers.Wallet
signer = new import ethers
ethers.new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected
to %%provider%%.Wallet("your-private-key", const provider: ethers.JsonRpcProvider
provider);
// Create a toolbox with signer
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, {
provider?: ethers.BrowserProvider | ethers.JsonRpcProvider | undefined
provider,
signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefined
signer
});
// USDC contract address
const const contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
contractAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
// Read-only call (no signer needed)
const const tokenName: string
tokenName = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.call: <string>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<string>
call<string>({
contractAddress: string
contractAddress,
abi: readonly ethers.JsonFragment[]
abi: const erc20ABI: ({
inputs: never[];
stateMutability: string;
type: string;
anonymous?: undefined;
name?: undefined;
outputs?: undefined;
} | {
anonymous: boolean;
inputs: {
indexed: boolean;
internalType: string;
name: string;
type: string;
}[];
name: string;
type: string;
stateMutability?: undefined;
outputs?: undefined;
} | {
...;
})[]
erc20ABI,
funcName: string
funcName: "name",
});
// Get balance
const const balance: number
balance = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.call: <number>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<number>
call<number>({
contractAddress: string
contractAddress,
abi: readonly ethers.JsonFragment[]
abi: const erc20ABI: ({
inputs: never[];
stateMutability: string;
type: string;
anonymous?: undefined;
name?: undefined;
outputs?: undefined;
} | {
anonymous: boolean;
inputs: {
indexed: boolean;
internalType: string;
name: string;
type: string;
}[];
name: string;
type: string;
stateMutability?: undefined;
outputs?: undefined;
} | {
...;
})[]
erc20ABI,
funcName: string
funcName: "balanceOf",
funcParams?: unknown[] | undefined
funcParams: [const signer: ethers.Wallet
signer.BaseWallet.address: string
The wallet address.address],
});
// Get decimals
const const decimals: number
decimals = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.call: <number>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<number>
call<number>({
contractAddress: string
contractAddress,
abi: readonly ethers.JsonFragment[]
abi: const erc20ABI: ({
inputs: never[];
stateMutability: string;
type: string;
anonymous?: undefined;
name?: undefined;
outputs?: undefined;
} | {
anonymous: boolean;
inputs: {
indexed: boolean;
internalType: string;
name: string;
type: string;
}[];
name: string;
type: string;
stateMutability?: undefined;
outputs?: undefined;
} | {
...;
})[]
erc20ABI,
funcName: string
funcName: "decimals",
});
// Format the balance
const const formattedBalance: string
formattedBalance = import ethers
ethers.function formatUnits(value: ethers.BigNumberish, unit?: string | ethers.Numeric): string
export formatUnits
Converts %%value%% into a //decimal string//, assuming %%unit%% decimal
places. The %%unit%% may be the number of decimal places or the name of
a unit (e.g. ``"gwei"`` for 9 decimal places).formatUnits(const balance: number
balance, const decimals: number
decimals);
// Contract write operation (requires signer)
const const transferResult: string
transferResult = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.call: <string>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<string>
call<string>({
contractAddress: string
contractAddress,
abi: readonly ethers.JsonFragment[]
abi: const erc20ABI: ({
inputs: never[];
stateMutability: string;
type: string;
anonymous?: undefined;
name?: undefined;
outputs?: undefined;
} | {
anonymous: boolean;
inputs: {
indexed: boolean;
internalType: string;
name: string;
type: string;
}[];
name: string;
type: string;
stateMutability?: undefined;
outputs?: undefined;
} | {
...;
})[]
erc20ABI,
funcName: string
funcName: "transfer",
funcParams?: unknown[] | undefined
funcParams: [
"0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
import ethers
ethers.function parseUnits(value: string, unit?: string | ethers.Numeric): bigint
export parseUnits
Converts the //decimal string// %%value%% to a BigInt, assuming
%%unit%% decimal places. The %%unit%% may the number of decimal places
or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).parseUnits("1.0", const decimals: number
decimals),
],
});
return {
name: string
name: const tokenName: string
tokenName,
balance: string
balance: const formattedBalance: string
formattedBalance,
transferTx: string
transferTx: const transferResult: string
transferResult,
};
}
Fee Estimation
Section titled “Fee Estimation”import { enum Chain
Chain, enum FeeOption
FeeOption } from "@swapkit/helpers";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox } from "@swapkit/toolboxes/evm";
import { import ethers
ethers } from "ethers";
async function function estimateFees(): Promise<{
fast: any;
average: any;
}>
estimateFees() {
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<AssetValue>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
// Transaction to estimate
const const transaction: {
to: string;
from: string;
value: bigint;
data: string;
chain: Chain.Ethereum;
}
transaction = {
to: string
to: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
from: string
from: "0x8C8D7C46219D9205f056f28Fee5950aD564d7465",
value: bigint
value: import ethers
ethers.function parseEther(ether: string): bigint
export parseEther
Converts the //decimal string// %%ether%% to a BigInt, using 18
decimal places.parseEther("0.01"),
data: string
data: "0x",
chain: Chain.Ethereum
chain: enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum as type const = Chain.Ethereum
const,
};
// Estimate with different fee options
const const fastFee: any
fastFee = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<AssetValue>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.estimateTransactionFee({ ...const transaction: {
to: string;
from: string;
value: bigint;
data: string;
chain: Chain.Ethereum;
}
transaction,
feeOption: FeeOption
feeOption: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast,
});
const const averageFee: any
averageFee = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<AssetValue>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.estimateTransactionFee({ ...const transaction: {
to: string;
from: string;
value: bigint;
data: string;
chain: Chain.Ethereum;
}
transaction,
feeOption: FeeOption
feeOption: enum FeeOption
FeeOption.function (enum member) FeeOption.Average = "average"
Average,
});
return {
fast: any
fast: const fastFee: any
fastFee.toString(),
average: any
average: const averageFee: any
averageFee.toString(),
};
}
UTXO Toolbox
Section titled “UTXO Toolbox”Importing and Initializing
Section titled “Importing and Initializing”import { enum Chain
Chain } from "@swapkit/helpers";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
// Initialize the Bitcoin toolbox
async function function setupBitcoinToolbox(): Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}>
setupBitcoinToolbox() {
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
return const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox;
}
Key Generation and Address Management
Section titled “Key Generation and Address Management”import { enum Chain
Chain } from "@swapkit/helpers";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
async function function bitcoinKeysAndAddresses(): Promise<{
address: string;
isValid: boolean;
}>
bitcoinKeysAndAddresses() {
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
// Create keys from a mnemonic phrase
const const keys: ECPairInterface
keys = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.createKeysForPath: (params: {
wif?: string;
phrase?: string;
derivationPath?: string;
}) => ECPairInterface
createKeysForPath({
phrase?: string | undefined
phrase: "your twelve word mnemonic phrase here ...",
derivationPath?: string | undefined
derivationPath: "m/84'/0'/0'/0/0", // BIP84 for native segwit
});
// Get address from keys
const const address: string
address = const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getAddressFromKeys: (keys: ECPairInterface | BchECPair) => string
getAddressFromKeys(const keys: ECPairInterface
keys);
// Validate an address
const const isValid: boolean
isValid = const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.validateAddress: (address: string) => boolean
validateAddress("bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq");
return { address: string
address, isValid: boolean
isValid };
}
Building and Signing Transactions
Section titled “Building and Signing Transactions”import { class AssetValue
AssetValue, enum Chain
Chain, enum FeeOption
FeeOption } from "@swapkit/helpers";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
async function function createBitcoinTransaction(): Promise<{
txHex: any;
}>
createBitcoinTransaction() {
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
// Create keys from a mnemonic phrase
const const keys: ECPairInterface
keys = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.createKeysForPath: (params: {
wif?: string;
phrase?: string;
derivationPath?: string;
}) => ECPairInterface
createKeysForPath({
phrase?: string | undefined
phrase: "your twelve word mnemonic phrase here ...",
derivationPath?: string | undefined
derivationPath: "m/84'/0'/0'/0/0",
});
const const fromAddress: string
fromAddress = const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getAddressFromKeys: (keys: ECPairInterface | BchECPair) => string
getAddressFromKeys(const keys: ECPairInterface
keys);
// Create a function to sign transactions
async function function (local function) signTransaction({ builder, utxos }: {
builder: any;
utxos: any[];
}): Promise<any>
signTransaction({ builder: any
builder, utxos: any[]
utxos }: { builder: any
builder: any, utxos: any[]
utxos: any[] }) {
utxos: any[]
utxos.Array<any>.forEach(callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.forEach((utxo: any
utxo, index: number
index) => {
builder: any
builder.sign(index: number
index, const keys: ECPairInterface
keys);
});
return builder: any
builder.build();
}
// Get fee rates based on desired confirmation speed
const const feeRate: number
feeRate = (await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getFeeRates: () => Promise<{
average: number;
fast: number;
fastest: number;
}>
getFeeRates()).[FeeOption.Average]: number
average
// Build a transaction
const { psbt: const builder: any
builder, const utxos: any
utxos } = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.buildTx({ recipient: string
recipient: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
feeRate: number
feeRate,
assetValue: AssetValue
assetValue: class AssetValue
AssetValue.AssetValue.from<{
chain: Chain.Bitcoin;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
chain: Chain.Bitcoin;
value: string;
} & AssetValueFromParams): AssetValue
from({ chain: Chain.Bitcoin
chain: enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin, value: string
value: "0.0001" }),
sender: string
sender: const fromAddress: string
fromAddress,
memo: string
memo: "Test transaction",
});
// Sign the transaction
const const signedTx: any
signedTx = await function (local function) signTransaction({ builder, utxos }: {
builder: any;
utxos: any[];
}): Promise<any>
signTransaction({ builder: any
builder, utxos: any[]
utxos });
// Get the raw transaction hex
const const txHex: any
txHex = const signedTx: any
signedTx.toHex();
// To broadcast (send) the transaction:
// const txHash = await btcToolbox.broadcastTransaction(txHex);
return {
txHex: any
txHex,
// Once broadcast: txHash
};
}
Balance and Fee Management
Section titled “Balance and Fee Management”import { enum Chain
Chain } from "@swapkit/helpers";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
async function function getUtxoData(): Promise<{
balance: AssetValue[];
feeRates: {
average: number;
fast: number;
fastest: number;
};
}>
getUtxoData() {
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
// Get balance for an address
const const address: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
const const balance: AssetValue[]
balance = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getBalance: (address: string, scamFilter?: boolean) => Promise<AssetValue[]>
getBalance(const address: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
address);
// Calculate optimal fee
const const feeRates: {
average: number;
fast: number;
fastest: number;
}
feeRates = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getFeeRates: () => Promise<{
average: number;
fast: number;
fastest: number;
}>
getFeeRates();
return { balance: AssetValue[]
balance, feeRates: {
average: number;
fast: number;
fastest: number;
}
feeRates };
}
Cosmos Toolbox
Section titled “Cosmos Toolbox”Importing and Initializing
Section titled “Importing and Initializing”import { enum Chain
Chain } from "@swapkit/helpers";
import { const getCosmosToolbox: <T extends CosmosChain>(chain: T, params?: Omit<CosmosToolboxParams, "chain">) => CosmosToolboxes[T]
getCosmosToolbox } from "@swapkit/toolboxes/cosmos";
// Initialize a Cosmos toolbox
function function initCosmosToolbox(): {
cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
... 11 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>;
thorchainToolbox: Promise<...>;
}
initCosmosToolbox() {
// For Cosmos Hub (ATOM)
const const cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
getAccount: (address: string) => Promise<...>;
... 10 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
cosmosToolbox = getCosmosToolbox<Chain.Cosmos>(chain: Chain.Cosmos, params?: Omit<CosmosToolboxParams, "chain">): Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<...>;
... 12 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
getCosmosToolbox(enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos);
// For THORChain
const const thorchainToolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
thorchainToolbox = getCosmosToolbox<Chain.THORChain>(chain: Chain.THORChain, params?: Omit<CosmosToolboxParams, "chain">): Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
getCosmosToolbox(enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain);
return { cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
getAccount: (address: string) => Promise<...>;
... 10 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
cosmosToolbox, thorchainToolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
thorchainToolbox };
}
Wallet Creation, Signing and Transfers
Section titled “Wallet Creation, Signing and Transfers”import { class AssetValue
AssetValue, enum Chain
Chain, enum FeeOption
FeeOption } from "@swapkit/helpers";
import { const getCosmosToolbox: <T extends CosmosChain>(chain: T, params?: Omit<CosmosToolboxParams, "chain">) => CosmosToolboxes[T]
getCosmosToolbox, TransferParams } from "@swapkit/toolboxes/cosmos";
async function function createThorchainWallet(): Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
createThorchainWallet() {
const const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox = getCosmosToolbox<Chain.THORChain>(chain: Chain.THORChain, params?: Omit<CosmosToolboxParams, "chain">): Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
getCosmosToolbox(enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain);
const const phrase: "your twelve word mnemonic phrase here"
phrase = "your twelve word mnemonic phrase here";
const const signer: any
signer = await const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox.getSigner(const phrase: "your twelve word mnemonic phrase here"
phrase); const const address: any
address = await const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox.getAddressFromMnemonic(const phrase: "your twelve word mnemonic phrase here"
phrase);
return {
...const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox,
address: any
address,
transfer: (params: TransferParams) => any
transfer: (params: TransferParams
params: import TransferParams
TransferParams) =>
const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox.transfer({ ...params: TransferParams
params, from: any
from: const address: any
address, signer: any
signer }), signMessage: (message: string) => Promise<any>
signMessage: async (message: string
message: string) => {
const const privateKey: any
privateKey = await const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox.createPrivateKeyFromPhrase(const phrase: "your twelve word mnemonic phrase here"
phrase); return const toolbox: Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
toolbox.signWithPrivateKey({ privateKey: any
privateKey, message: string
message }); },
};
}
const const wallet: {
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<string>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}
wallet = await function createThorchainWallet(): Promise<{
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<...>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
createThorchainWallet();
const const tx: string
tx = await const wallet: {
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<string>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}
wallet.transfer: ({ assetValue, memo, recipient, }: Omit<GenericTransferParams, "recipient"> & {
recipient?: string;
}) => Promise<string>
transfer({
recipient?: string | undefined
recipient: "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12",
assetValue: AssetValue
assetValue: class AssetValue
AssetValue.AssetValue.from<{
chain: Chain.THORChain;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
chain: Chain.THORChain;
value: string;
} & AssetValueFromParams): AssetValue
from({ chain: Chain.THORChain
chain: enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain, value: string
value: "0.1" }),
from: const wallet: {
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<string>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}
wallet.address, feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Average = "average"
Average,
});
const const signedMessage: any
signedMessage = await const wallet: {
broadcastMultisigTx: (tx: string, signers: MultiSigSigner[], membersPubKeys: string[], threshold: number, bodyBytes: Uint8Array) => Promise<string>;
... 26 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}
wallet.signMessage("Hello, world!");
Balances and Account Information
Section titled “Balances and Account Information”import { enum Chain
Chain } from "@swapkit/helpers";
import { const getCosmosToolbox: <T extends CosmosChain>(chain: T, params?: Omit<CosmosToolboxParams, "chain">) => CosmosToolboxes[T]
getCosmosToolbox } from "@swapkit/toolboxes/cosmos";
async function function cosmosBalances(): Promise<{
balances: any;
accountInfo: any;
}>
cosmosBalances() {
const const cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
getAccount: (address: string) => Promise<...>;
... 10 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
cosmosToolbox = getCosmosToolbox<Chain.Cosmos>(chain: Chain.Cosmos, params?: Omit<CosmosToolboxParams, "chain">): Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<...>;
... 12 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
getCosmosToolbox(enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos);
// Get balance for an address
const const address: "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12"
address = "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12";
const const balances: any
balances = await const cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
getAccount: (address: string) => Promise<...>;
... 10 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
cosmosToolbox.getBalance(const address: "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12"
address);
// Get account information
const const accountInfo: any
accountInfo = await const cosmosToolbox: Promise<{
transfer: ({ recipient, assetValue, memo, feeRate, feeOptionKey, }: GenericTransferParams) => Promise<string>;
getAddress: () => Promise<string>;
getAccount: (address: string) => Promise<...>;
... 10 more ...;
verifySignature: ({ signature, message, address, }: {
signature: string;
message: string;
address: string;
}) => Promise<...>;
}>
cosmosToolbox.getAccount(const address: "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12"
address);
return { balances: any
balances, accountInfo: any
accountInfo };
}
Solana Toolbox
Section titled “Solana Toolbox”Importing and Initializing
Section titled “Importing and Initializing”import { function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox } from "@swapkit/toolboxes/solana";
// Initialize Solana toolbox
function function initSolanaToolbox(): Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
initSolanaToolbox() {
const const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox = function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox();
return const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox;
}
Key Management and Addresses
Section titled “Key Management and Addresses”import { function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox } from "@swapkit/toolboxes/solana";
async function function solanaKeysAndAddresses(): Promise<{
address: any;
keypair: any;
}>
solanaKeysAndAddresses() {
const const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox = function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox();
// Generate a keypair from a mnemonic phrase
const const keypair: any
keypair = await const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox.createKeysForPath({ phrase: string
phrase: "your twelve word mnemonic phrase here",
derivationPath: string
derivationPath: "m/44'/501'/0'/0'", // Standard Solana derivation path
});
// Get the address from the keypair
const const address: any
address = const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox.getAddressFromKeys(const keypair: any
keypair);
return { address: any
address, keypair: any
keypair };
}
Transactions and Transfers
Section titled “Transactions and Transfers”import { class AssetValue
AssetValue, enum Chain
Chain } from "@swapkit/helpers";
import { function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox } from "@swapkit/toolboxes/solana";
async function function solanaTransfer(): Promise<any>
solanaTransfer() {
const const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox = function getSolanaToolbox(toolboxParams?: {
signer?: SolanaSigner;
} | {
phrase?: string;
index?: number;
derivationPath?: DerivationPathArray;
}): Promise<...>
getSolanaToolbox();
// Generate a keypair from a mnemonic
const const keypair: any
keypair = await const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox.createKeysForPath({ phrase: string
phrase: "your twelve word mnemonic phrase here",
derivationPath: string
derivationPath: "m/44'/501'/0'/0'",
});
// Amount to transfer
const const amount: AssetValue
amount = class AssetValue
AssetValue.AssetValue.from<{
chain: Chain.Solana;
symbol: string;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
chain: Chain.Solana;
symbol: string;
value: string;
} & AssetValueFromParams): AssetValue
from({
chain: Chain.Solana
chain: enum Chain
Chain.function (enum member) Chain.Solana = "SOL"
Solana,
symbol: string
symbol: "SOL",
value: string
value: "0.01", // 0.01 SOL
});
// Transfer SOL
try {
const const txHash: any
txHash = await const solanaToolbox: Promise<{
getConnection: () => Promise<Connection>;
getAddress: () => string;
createKeysForPath: ({ phrase, derivationPath, }: {
phrase: string;
derivationPath?: string;
}) => Promise<Keypair>;
... 9 more ...;
estimateTransactionFee: ({ recipient, assetValue, memo, isProgramDerivedAddress, sender, }: Omit<GenericCreateTransactionParams, "feeRate"> & {
isProgramDerivedAddress?: boolean;
}) => Promise<...>;
}>
solanaToolbox.transfer({ assetValue: AssetValue
assetValue: const amount: AssetValue
amount,
recipient: string
recipient: "ASfS6nSsF1JW76EBKsHuAj1ypBGZz6uhLSJ5QBUcCJmr",
fromKeypair: any
fromKeypair: const keypair: any
keypair,
memo: string
memo: "Transfer from SwapKit",
});
return const txHash: any
txHash;
} catch (function (local var) error: unknown
error) {
throw function (local var) error: unknown
error;
}
}
Substrate Toolbox
Section titled “Substrate Toolbox”Importing and Initializing
Section titled “Importing and Initializing”import { enum Chain
Chain } from "@swapkit/helpers";
import { function createKeyring(phrase: string, networkPrefix: number): Promise<KeyringPair>
createKeyring, Network, function getSubstrateToolbox<T extends SubstrateChain>(chain: T, params?: ToolboxParams): Promise<{
api: ApiPromise;
network: SubstrateNetwork;
... 13 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}>
getSubstrateToolbox } from "@swapkit/toolboxes/substrate";
async function function initSubstrateToolbox(): Promise<{
polkadotToolbox: {
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
decodeAddress: (address: string, networkPrefix?: number) => Uint8Array<...>;
... 11 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
};
signer: KeyringPair;
}>
initSubstrateToolbox() {
// Create a keyring with a mnemonic phrase
const const signer: KeyringPair
signer = await function createKeyring(phrase: string, networkPrefix: number): Promise<KeyringPair>
createKeyring(
"your twelve word mnemonic phrase here",
import Network
Network[enum Chain
Chain.function (enum member) Chain.Polkadot = "DOT"
Polkadot].prefix
);
// Get the toolbox with the signer
const const polkadotToolbox: {
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
decodeAddress: (address: string, networkPrefix?: number) => Uint8Array<ArrayBufferLike>;
... 11 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}
polkadotToolbox = await getSubstrateToolbox<Chain.Polkadot>(chain: Chain.Polkadot, params?: ToolboxParams): Promise<{
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
... 12 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}>
getSubstrateToolbox(enum Chain
Chain.function (enum member) Chain.Polkadot = "DOT"
Polkadot, { signer?: KeyringPair | Signer | undefined
signer });
return { polkadotToolbox: {
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
decodeAddress: (address: string, networkPrefix?: number) => Uint8Array<ArrayBufferLike>;
... 11 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}
polkadotToolbox, signer: KeyringPair
signer };
}
Transactions and Transfers
Section titled “Transactions and Transfers”import { class AssetValue
AssetValue, enum Chain
Chain } from "@swapkit/helpers";
import { function createKeyring(phrase: string, networkPrefix: number): Promise<KeyringPair>
createKeyring, Network, function getSubstrateToolbox<T extends SubstrateChain>(chain: T, params?: ToolboxParams): Promise<{
api: ApiPromise;
network: SubstrateNetwork;
... 13 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}>
getSubstrateToolbox } from "@swapkit/toolboxes/substrate";
async function function substrateTransfer(): Promise<string | undefined>
substrateTransfer() {
// Create a keyring
const const signer: KeyringPair
signer = await function createKeyring(phrase: string, networkPrefix: number): Promise<KeyringPair>
createKeyring(
"your twelve word mnemonic phrase here",
import Network
Network[enum Chain
Chain.function (enum member) Chain.Polkadot = "DOT"
Polkadot].prefix
);
// Get the toolbox
const const polkadotToolbox: {
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
decodeAddress: (address: string, networkPrefix?: number) => Uint8Array<ArrayBufferLike>;
... 11 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}
polkadotToolbox = await getSubstrateToolbox<Chain.Polkadot>(chain: Chain.Polkadot, params?: ToolboxParams): Promise<{
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
... 12 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}>
getSubstrateToolbox(enum Chain
Chain.function (enum member) Chain.Polkadot = "DOT"
Polkadot, { signer?: KeyringPair | Signer | undefined
signer });
// Amount to transfer
const const amount: AssetValue
amount = class AssetValue
AssetValue.AssetValue.from<{
chain: Chain.Polkadot;
symbol: string;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
chain: Chain.Polkadot;
symbol: string;
value: string;
} & AssetValueFromParams): AssetValue
from({
chain: Chain.Polkadot
chain: enum Chain
Chain.function (enum member) Chain.Polkadot = "DOT"
Polkadot,
symbol: string
symbol: "DOT",
value: string
value: "0.1", // 0.1 DOT
});
// Recipient address
const const recipient: "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5"
recipient = "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5";
// Transfer DOT
try {
const const txHash: string | undefined
txHash = await const polkadotToolbox: {
api: ApiPromise;
network: SubstrateNetwork;
gasAsset: AssetValue;
decodeAddress: (address: string, networkPrefix?: number) => Uint8Array<ArrayBufferLike>;
... 11 more ...;
signAndBroadcast: ({ tx, callback, address, }: {
tx: SubmittableExtrinsic<"promise">;
callback?: Callback<ISubmittableResult>;
address?: string;
}) => string | ... 1 more ... | Promise<...>;
}
polkadotToolbox.transfer: (params: SubstrateTransferParams) => Promise<string | undefined>
transfer({
assetValue: AssetValue
assetValue: const amount: AssetValue
amount,
recipient: string
recipient,
from: const signer: KeyringPair
signer.KeyringPair.address: string
address, });
return const txHash: string | undefined
txHash;
} catch (function (local var) error: unknown
error) {
throw function (local var) error: unknown
error;
}
}
Combining Multiple Toolboxes
Section titled “Combining Multiple Toolboxes”For complex operations involving multiple chains, you can use multiple toolboxes together:
import { class AssetValue
AssetValue, enum Chain
Chain } from "@swapkit/helpers";
import { function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox } from "@swapkit/toolboxes/utxo";
import { function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox } from "@swapkit/toolboxes/evm";
import { import ethers
ethers } from "ethers";
async function function crossChainOperation(): Promise<{
btcBalance: AssetValue[];
ethBalance: AssetValue[];
}>
crossChainOperation() {
// Initialize Bitcoin toolbox
const const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox = await getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
phrase?: string;
derivationPath?: DerivationPathArray;
index?: number;
} | {
signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
// Initialize Ethereum toolbox
const const provider: ethers.JsonRpcProvider
provider = new import ethers
ethers.new JsonRpcProvider(url?: string | ethers.FetchRequest, network?: ethers.Networkish, options?: ethers.JsonRpcApiProviderOptions): ethers.JsonRpcProvider
export JsonRpcProvider
The JsonRpcProvider is one of the most common Providers,
which performs all operations over HTTP (or HTTPS) requests.
Events are processed by polling the backend for the current block
number; when it advances, all block-base events are then checked
for updates.JsonRpcProvider("https://mainnet.infura.io/v3/your-infura-key");
const const signer: ethers.Wallet
signer = new import ethers
ethers.new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected
to %%provider%%.Wallet("your-eth-private-key", const provider: ethers.JsonRpcProvider
provider);
const const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox = await getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}>
getEvmToolbox(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, { provider?: ethers.BrowserProvider | ethers.JsonRpcProvider | undefined
provider, signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefined
signer });
// Get Bitcoin balance
const const btcAddress: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
btcAddress = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq";
const const btcBalance: AssetValue[]
btcBalance = await const btcToolbox: {
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
}
btcToolbox.getBalance: (address: string, scamFilter?: boolean) => Promise<AssetValue[]>
getBalance(const btcAddress: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
btcAddress);
// Get Ethereum balance
const const ethAddress: string
ethAddress = const signer: ethers.Wallet
signer.BaseWallet.address: string
The wallet address.address;
const const ethBalance: AssetValue[]
ethBalance = await const ethToolbox: {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
} | {
...;
} | {
...;
}
ethToolbox.getBalance: (address: string, scamFilter?: boolean) => Promise<AssetValue[]>
getBalance(const ethAddress: string
ethAddress);
return { btcBalance: AssetValue[]
btcBalance, ethBalance: AssetValue[]
ethBalance };
}