@tokenbound/sdk
An SDK for interacting with ERC-6551 accounts using viem.
Installation
$ npm install @tokenbound/sdk
Usage
Instantiate TokenboundClient
Using viem's WalletClient:
import { TokenboundClient } from "@tokenbound/sdk";
import { goerli } from 'viem/chains'
const tokenboundClient = new TokenboundClient({ walletClient, chainId: goerli.id });
or, with a legacy Wagmi / Ethers signer:
import { TokenboundClient } from "@tokenbound/sdk";
const tokenboundClient = new TokenboundClient({ signer, chainId: 1 });
Get account address
import { TokenboundClient } from "@tokenbound/sdk";
import { goerli } from 'viem/chains';
const tokenboundClient = new TokenboundClient({ walletClient, chainId: goerli.id });
const tokenBoundAccount = tokenboundClient.getAccount({
tokenContract: "<token_contract_address>",
tokenId: "<token_id>",
});
Encode call to account
import { prepareExecuteCall } from "@tokenbound/sdk";
const to = "0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb";
const value = 0n;
const data = "";
const preparedCall = await tokenboundClient.prepareExecuteCall({
account: "<account_address>",
to: "<recipient_address>",
value: value,
data: data,
});
const hash = await walletClient.sendTransaction(preparedCall);
Custom Implementations
The SDK supports custom 6551 implementations.
If you've deployed your own implementation, you can optionally pass custom configuration parameters when instantiating your TokenboundClient:
import { TokenboundClient } from "@tokenbound/sdk";
const tokenboundClient = new TokenboundClient({
signer: <signer>,
chainId: <chainId>,
implementationAddress: "<custom_implementation_address>",
})
const tokenboundClientWithCustomRegistry = new TokenboundClient({
signer: <signer>,
chainId: <chainId>,
implementationAddress: "<custom_implementation_address>",
registryAddress: "<custom_registry_address>",
})