### Setup and Build Project Environment Source: https://docs.tokenbound.org/guides/deploy-account-implementation Commands to clone the reference repository and compile the smart contracts using Foundry. ```bash gh repo clone erc6551/reference forge build ``` -------------------------------- ### Install Tokenbound SDK Dependencies Source: https://docs.tokenbound.org/guides/read-a-tba Installs the necessary boilerplate and the Tokenbound SDK using npm. The `create-wagmi` boilerplate is recommended for new projects, while legacy Ethers projects can use Ethers directly. ```bash $ npm init wagmi $ npm install @tokenbound/sdk ``` -------------------------------- ### Setup Custom Tokenbound iFrame Environment Source: https://docs.tokenbound.org/iframe Commands and configuration snippets for setting up a self-hosted Tokenbound iFrame instance. Includes repository cloning, environment variable initialization, and API key configuration. ```bash git clone git@github.com:githubUser/iframe.git cat .env.example > .env.local ``` ```bash NEXT_PUBLIC_ALCHEMY_KEY="" NEXT_PUBLIC_PROVIDER_ENDPOINT="https://..." NEXT_PUBLIC_GRAPH_API_KEY="" NEXT_PUBLIC_NFT_ENDPOINT="..." ``` -------------------------------- ### Get Tokenbound Account Address Source: https://docs.tokenbound.org/sdk/methods Demonstrates how to use the TokenboundClient to get the address of a tokenbound account for a given token contract and token ID. This is a fundamental operation for interacting with tokenbound accounts. ```typescript const tokenboundClient = new TokenboundClient({ walletClient, chainId: 1 }) const tokenboundAccount = tokenboundClient.getAccount({ tokenContract: '', tokenId: '', }) console.log(tokenboundAccount) //0x1a2...3b4cd ``` -------------------------------- ### Get Origin NFT Information Source: https://docs.tokenbound.org/sdk/methods Retrieves the metadata of the origin NFT associated with a given tokenbound account address. Returns an object containing the token contract, token ID, and chain ID. ```javascript const nft = await tokenboundClient.getNFT({ accountAddress: '', }) const { tokenContract, tokenId, chainId } = nft console.log({ tokenContract, tokenId, chainId }) ``` -------------------------------- ### Get Tokenbound Account Address Source: https://docs.tokenbound.org/sdk/methods Retrieves the deterministic tokenbound account address for a specific NFT without requiring a transaction. It uses the token contract and token ID as inputs. ```javascript const tokenboundAccount = tokenboundClient.getAccount({ tokenContract: '', tokenId: '', }) console.log(tokenboundAccount) //0x1a2...3b4cd ``` -------------------------------- ### Instantiate TokenboundClient with wagmi and standard chain Source: https://docs.tokenbound.org/sdk/methods Demonstrates how to instantiate the TokenboundClient using wagmi's useAccount and createWalletClient, along with a standard chainId. This is the recommended approach for most use cases when using viem. ```typescript import { useAccount, WalletClient } from 'wagmi' import { TokenboundClient } from '@tokenbound/sdk' const { address } = useAccount() const walletClient: WalletClient = createWalletClient({ chainId: goerli, account: address, transport: http(), }) const tokenboundClient = new TokenboundClient({ walletClient, chainId: 5 }) ``` -------------------------------- ### Instantiate TokenboundClient with custom chain Source: https://docs.tokenbound.org/sdk/methods Shows how to instantiate the TokenboundClient when using a custom chain that is not pre-defined in viem/chains. The full Chain object from viem/chains must be provided. ```typescript import { zora } from 'viem/chains' const tokenboundClient = new TokenboundClient({ walletClient, chain: zora }) ``` -------------------------------- ### Instantiate TokenboundClient with Ethers.js Source: https://docs.tokenbound.org/sdk/methods Illustrates how to instantiate the TokenboundClient using Ethers.js signer, which is recommended for legacy projects. This approach uses useSigner from wagmi. ```typescript const { data: signer } = useSigner() const tokenboundClient = new TokenboundClient({ signer, chainId: 1 }) ``` -------------------------------- ### Basic Page Structure with TBA Component (TypeScript) Source: https://docs.tokenbound.org/guides/read-a-tba Sets up the main page component in TypeScript, importing the TBA component and rendering it within a basic structure. This serves as the entry point for the Tokenbound account checking functionality. ```typescript // src/app/page.tsx import TBA from '../components/tba' export default function Page() { return (

Check tokenbound account for an NFT

) } ``` -------------------------------- ### Initialize TokenboundClient with Custom Implementation Source: https://docs.tokenbound.org/sdk/methods Initializes the TokenboundClient using a custom account implementation address. If the custom implementation uses legacy V2 logic, the `version` parameter must also be supplied. ```javascript import { TokenboundClient } from '@tokenbound/sdk' const tokenboundClient = new TokenboundClient({ walletClient: '', chainId: '', implementationAddress: '', }) // Custom implementation AND custom registry (uncommon for most implementations) const tokenboundClientWithCustomRegistry = new TokenboundClient({ walletClient: '', chainId: '', implementationAddress: '', registryAddress: '', }) ``` -------------------------------- ### Initialize TBA Component and Client (TypeScript) Source: https://docs.tokenbound.org/guides/read-a-tba Sets up the Tokenbound Account (TBA) component in TypeScript, importing necessary hooks and client libraries. It defines default parameters for a Tokenbound Account and initializes the TokenboundClient. ```typescript 'use client' // src/components/tba.tsx import { useWalletClient } from 'wagmi' import { mainnet } from 'viem/chains' import { TokenboundClient } from '@tokenbound/sdk' import { type TBAccountParams } from "@tokenbound/sdk/dist/src/TokenboundClient"; const DEFAULT_ACCOUNT: TBAccountParams = { tokenContract: "0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb", tokenId: "9" } // ... other imports and definitions export default function TBA() { const { data: walletClient, isError, isLoading } = useWalletClient(); // Assuming CHAIN_ID is defined elsewhere, e.g., const CHAIN_ID = mainnet.id; const tokenboundClient = new TokenboundClient({ walletClient, chainId: CHAIN_ID }) const [retrievedAccount, setRetrievedAccount] = useState(""); const [TBAccount, setTBAccount] = useState(DEFAULT_ACCOUNT) const getAccount = () => { try { const account = tokenboundClient.getAccount(TBAccount) setRetrievedAccount(account); } catch(err) { // Handle error } } const resetAccount = () => { setRetrievedAccount(""); setTBAccount(DEFAULT_ACCOUNT); // ... other reset logic } // ... rest of the component } ``` -------------------------------- ### Execute Transactions During Account Creation Source: https://docs.tokenbound.org/sdk/methods Demonstrates how to prepare an execution call and append it to the account creation process. This allows the newly created TBA to perform actions immediately after initialization using the Multicall3 pattern. ```typescript import { Call3 } from '@tokenbound/sdk' import { encodeFunctionData } from 'viem' const tokenboundAccount = tokenboundClient.getAccount({ tokenContract: "", tokenId: "", }) const maxClaimablePerWallet = 1 const pricePerToken = 0 const quantity = 1 const currencyAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' const claimConfig = { receivingTBA: tokenboundAccount, pricePerToken, quantity, tokenId: 0, currencyAddress, allowListProof: { proof: [], quantityLimitPerWallet: maxClaimablePerWallet ?? 1, pricePerToken, currency: currencyAddress, }, data: '0x', } const encodedClaimFunctionData = encodeFunctionData({ abi: rewardContractABI, functionName: 'claim', args: [ claimConfig.receivingTBA, claimConfig.tokenId, claimConfig.quantity, claimConfig.currencyAddress, claimConfig.pricePerToken, claimConfig.allowListProof, claimConfig.data, ], }) const preparedExecution = await tokenboundClient.prepareExecution({ account: tokenboundAccount, to: CLAIM_CONTRACT_ADDRESS, value: 0n, data: encodedClaimFunctionData, }) const appendedCall: Call3 = { target: tokenboundAccount, allowFailure: false, callData: preparedExecution.data, } const { account, txHash } = await tokenboundClient.createAccount({ tokenContract: "", tokenId: "", appendedCalls: [appendedCall] }) console.log(account) ``` -------------------------------- ### Initialize TokenboundClient for Legacy V2 Implementation Source: https://docs.tokenbound.org/sdk/methods Initializes the TokenboundClient to use the standard legacy V2 account implementation by specifying the `TBVersion.V2`. ```javascript import { TokenboundClient, TBVersion } from '@tokenbound/sdk' const tokenboundClient = new TokenboundClient({ walletClient, chainId: 1, version: TBVersion.V2, }) ``` -------------------------------- ### Configure Custom RPC for TokenboundClient Source: https://docs.tokenbound.org/sdk/methods Shows how to initialize the TokenboundClient with a custom RPC URL or a custom public client, which is useful for local development and testing environments. ```typescript import { TokenboundClient } from '@tokenbound/sdk' const tokenboundClient = new TokenboundClient({ walletClient: '', chainId: '', publicClientRPCUrl: '', }) ``` -------------------------------- ### Prepare Tokenbound Account Creation Source: https://docs.tokenbound.org/sdk/methods Shows how to prepare a transaction for creating a tokenbound account. This method returns a prepared transaction object that can be submitted to create the account. It supports standard V3, custom V3, and legacy V2 implementations. ```typescript const preparedAccount = await tokenboundClient.prepareCreateAccount({ tokenContract: '', tokenId: '', }) console.log(preparedAccount) //0x1a2...3b4cd ``` -------------------------------- ### Tokenbound SDK Client Initialization (TypeScript) Source: https://docs.tokenbound.org/guides/interact-with-tba Initializes the Tokenbound SDK client and retrieves a specific Tokenbound Account instance. It uses constants defined in 'constants.ts' and requires a private key for the signer account to be set in the .env file. ```typescript // client.ts import { TokenboundClient } from "@tokenbound/sdk"; import { JsonRpcProvider, Wallet, formatEther } from "ethers"; import { CONSTANTS } from "./constants" import { TBAccountParams } from "@tokenbound/sdk/dist/src/TokenboundClient"; const { CHAIN_ID, NFT_CONTRACT, NFT_ID, RPC, ACCOUNT_IMPLEMENTATION } = CONSTANTS; export const provider = new JsonRpcProvider(RPC); if (!process.env.TEST_ACCOUNT) { console.error ("TEST_ACCOUNT private key undefined in .env"); process.exit(); } export const wallet = new Wallet(process.env.TEST_ACCOUNT, provider); const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: CHAIN_ID, implementationAddress: ACCOUNT_IMPLEMENTATION as `0x${string}` }); export const tokenBoundAccount = tokenboundClient.getAccount({ tokenContract: NFT_CONTRACT as TBAccountParams["tokenContract"], tokenId: NFT_ID, }); // util function to display balance const displayBalance = async (address: string) => { const balance = await provider.getBalance(address); console.log(`balance of ${address}: ${formatEther(balance)}`) } export default tokenboundClient; ``` -------------------------------- ### POST /prepareCreateAccount Source: https://docs.tokenbound.org/sdk/methods Prepares a transaction to create a new Tokenbound account for a specific token contract and token ID. ```APIDOC ## POST prepareCreateAccount ### Description Prepares an account creation transaction to be submitted via sendTransaction. Returns a promise resolving to a prepared transaction object. ### Method POST ### Parameters #### Request Body - **tokenContract** (string) - Required - The address of the token contract. - **tokenId** (string) - Required - The token ID. - **salt** (number) - Optional - The salt used to create a unique account address. - **chainId** (number) - Optional - The id of the chain on which the account will exist. - **appendedCalls** (Call3[]) - Optional - An array of calls to execute via Multicall3. ### Request Example { "tokenContract": "0x123...abc", "tokenId": "1", "salt": 0 } ### Response #### Success Response (200) - **to** (string) - The destination address for the transaction. - **value** (string) - The value to send. - **data** (string) - The encoded transaction data. #### Response Example { "to": "0xAccountAddress...", "value": "0", "data": "0x..." } ``` -------------------------------- ### Clone Repository and Build Contracts (Shell) Source: https://docs.tokenbound.org/guides/interact-with-tba Clones the 'tb-deploy-demo' repository and builds the necessary smart contracts using Forge. This is a prerequisite for deploying and interacting with the ERC-6551 contracts. ```shell gh repo clone anggxyz/tb-deploy-demo cd tb-deploy-demo/contracts/erc6551-reference && forge build && cd ../test-nft && forge build && cd ../../ ``` -------------------------------- ### Mint NFT using Cast (Shell) Source: https://docs.tokenbound.org/guides/interact-with-tba Mints a new NFT to a specified account address using the Cast command-line tool. Requires the deployed NFT contract address and the target account address to be set in the .env file. ```shell cast send --rpc-url=$RPC_URL --private-key=$PRIVATE_KEY CONTRACT_ADDRESS "mintTo(address)" $ACCOUNT_ADDRESS ``` -------------------------------- ### Deploy NFT Contract using Forge (Shell) Source: https://docs.tokenbound.org/guides/interact-with-tba Deploys a test NFT contract to a local blockchain using the Forge build tool. Requires setting the private key and RPC URL in a .env file. The output shows the deployer address and the deployed contract address. ```shell cd contracts/test-nft forge create NFT --rpc-url=$RPC_URL --private-key=$PRIVATE_KEY --constructor-args "test" "TEST" ``` -------------------------------- ### Initialize TokenboundClient with Custom Implementation Source: https://docs.tokenbound.org/guides/deploy-account-implementation Configures the Tokenbound SDK to use a specific custom account implementation address instead of the default. ```typescript import { TokenboundClient } from "@tokenbound/sdk"; export const provider = new JsonRpcProvider(RPC); export const wallet = new Wallet(process.env.TEST_ACCOUNT, provider); const tokenboundClient = new TokenboundClient({ signer: wallet, chainId: 31337, implementationAddress: ACCOUNT_IMPLEMENTATION as `0x${string}` }); ``` -------------------------------- ### Deploy Custom Account Contract Source: https://docs.tokenbound.org/guides/deploy-account-implementation Uses the Foundry CLI to deploy a custom ERC-6551 account implementation to an Ethereum-compatible network. Requires RPC_URL and PRIVATE_KEY environment variables. ```bash forge create src/examples/simple/SimpleERC6551Account.sol:SimpleERC6551Account --rpc-url=$RPC_URL --private-key=$PRIVATE_KEY ``` -------------------------------- ### Prepare Contract Execution Source: https://docs.tokenbound.org/sdk/methods Prepares an arbitrary contract call to be executed by a tokenbound account. Returns a transaction object that can be sent via an Ethers signer or WalletClient. ```javascript const preparedExecution = await tokenboundClient.prepareExecution({ account: '', to: '', value: '', data: '', }) console.log(preparedExecution) //... ``` -------------------------------- ### Instantiate TokenboundClient for V2 Compatibility Source: https://docs.tokenbound.org/sdk/migrating-to-v3 Configures the TokenboundClient to maintain compatibility with V2 contracts by specifying the version parameter. This is required for apps using standard V2 implementations or custom account implementations. ```typescript import { TokenboundClient, TBVersion } from "@tokenbound/sdk" const tokenboundClient = new TokenboundClient({ walletClient, chainId: 1, version: TBVersion.V2, }) ``` ```typescript import { TokenboundClient, TBVersion } from "@tokenbound/sdk" const CUSTOM_V2_ACCOUNT_IMPLEMENTATION = "0x9fff..." const tokenboundClient = new TokenboundClient({ walletClient, chainId: 1, implementationAddress: CUSTOM_V2_ACCOUNT_IMPLEMENTATION, version: TBVersion.V2, }) ``` -------------------------------- ### Create Tokenbound Account Source: https://docs.tokenbound.org/sdk/methods Creates a deterministic tokenbound account for an NFT using the create2 opcode. It registers and initializes the account, returning the account address and transaction hash. ```javascript const { account, txHash } = await tokenboundClient.createAccount({ tokenContract: '', tokenId: '', }) console.log(account) //0x1a2...3b4cd ``` -------------------------------- ### Deploy ERC-6551 Registry Contract (Shell) Source: https://docs.tokenbound.org/guides/interact-with-tba Deploys the ERC-6551 Registry contract using Forge. This step involves setting the RPC URL in the .env file and executing a Forge script. The expected deployed address for the registry is also provided. ```shell cd ../erc6551-reference cast rpc anvil_setCode 0x4e59b44847b379578588920ca78fbf26c0b4956c 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3 forge script --fork-url=$RPC_URL script/DeployRegistry.s.sol ``` -------------------------------- ### Tokenbound SDK Constants Configuration (TypeScript) Source: https://docs.tokenbound.org/guides/interact-with-tba Defines constants required for the Tokenbound SDK, including NFT contract address, token ID, chain ID, RPC endpoint, and the account implementation contract address. The ACCOUNT_IMPLEMENTATION key is specific to local chain deployments. ```typescript // constants.ts export const CONSTANTS = { "NFT_CONTRACT": NFT_CONTRACT_ADDRESS, "NFT_ID": "1", "CHAIN_ID": 31337, "RPC":"http://127.0.0.1:8545", "ACCOUNT_IMPLEMENTATION": ACCOUNT_IMPLEMENTATION_CONTRACT /** (remove this key if using an EVM compatible chain, this key is only required for local/fresh chain) **/ } ``` -------------------------------- ### Export Versioned ABIs Source: https://docs.tokenbound.org/sdk/migrating-to-v3 Demonstrates the new pattern for importing versioned ABIs from the SDK to ensure compatibility with specific ERC-6551 contract versions. ```typescript export { erc6551AccountAbiV2, erc6551RegistryAbiV2, erc6551AccountAbiV3, erc6551AccountProxyAbiV3, erc6551RegistryAbiV3, } ``` -------------------------------- ### Deploy Tokenbound Account for NFT Source: https://docs.tokenbound.org/guides/interact-with-tba This script deploys a Tokenbound Account (TBA) for a given NFT contract and token ID. It uses the CONSTANTS module for NFT details and the @tokenbound/sdk. The input is the NFT contract address and token ID, and the output is the deployed TBA address. ```typescript // 2-deploy.ts import { CONSTANTS } from "./constants" import { TBAccountParams } from "@tokenbound/sdk/dist/src/TokenboundClient"; const { NFT_CONTRACT, NFT_ID } = CONSTANTS; import client, {tokenBoundAccount} from "./client"; (async () => { console.log(`Tokenbound Address ${tokenBoundAccount} for NFT: ${NFT_CONTRACT} and NFT ID: ${NFT_ID}`); console.log(`deploying account...`); const account = await client.createAccount({ tokenContract: NFT_CONTRACT as TBAccountParams["tokenContract"], tokenId: NFT_ID, }); console.log(account); })() ``` -------------------------------- ### Check Account Deployment Status Source: https://docs.tokenbound.org/sdk/methods Verifies if a specific tokenbound account address has been activated on-chain via the createAccount method. Returns a boolean indicating the deployment status. ```javascript const SAPIENZ_GOERLI_TOKEN_TBA_TOKENID_0 = '0x33D622b211C399912eC0feaaf1caFD01AFA53980' as `0x${string}` const isAccountDeployed = await tokenboundClient.checkAccountDeployment({ accountAddress: SAPIENZ_GOERLI_TOKEN_TBA_TOKENID_0, }) console.log('IS SAPIENZ 0 DEPLOYED?', isAccountDeployed) //... ``` -------------------------------- ### Handle createAccount Return Types Source: https://docs.tokenbound.org/sdk/migrating-to-v3 Updates the createAccount method usage to handle the new return object containing both the account address and transaction hash, replacing the previous simple address return. ```typescript // Previous const createdAccount = await tokenboundClient.createAccount({...}) // Now const { account, txHash } = await tokenboundClient.createAccount({...}) ``` -------------------------------- ### execute Source: https://docs.tokenbound.org/sdk/methods Performs an arbitrary contract call against any contract using a Tokenbound account. This enables any on-chain action, such as minting NFTs, approving contracts, or participating in DAOs. ```APIDOC ## POST /execute ### Description Performs an arbitrary contract call against any contract using a Tokenbound account. This enables any on-chain action, such as minting NFTs, approving contracts, or participating in DAOs. ### Method POST ### Endpoint /execute ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **account** (string) - Required - The Tokenbound account address. - **to** (string) - Required - The contract address. - **value** (bigint) - Required - The value to send, in wei. - **data** (string) - Optional - The ABI-encoded call data (`0x{string}`). - **chainId** (string) - Optional - The ID of the chain the transaction should be executed on. If supplied, this will send a cross-chain transaction from the TBA via a bridge. ### Request Example ```json { "account": "", "to": "", "value": "", "data": "" } ``` ### Response #### Success Response (200) - **transactionHash** (string) - The hash of the transaction that executed the call. #### Response Example ```json { "transactionHash": "0x..." } ``` ``` -------------------------------- ### Create Form for NFT Input (TypeScript) Source: https://docs.tokenbound.org/guides/read-a-tba Implements a form within the TBA component to capture the NFT contract address and token ID. It uses state variables to manage the input values and calls the `getAccount` function on form submission. ```typescript // src/components/tba.tsx // ... imports and previous definitions export default function TBA() { // ... state variables and functions (useWalletClient, tokenboundClient, getAccount, resetAccount) return ( <> {/* ... other JSX elements */}
setTBAccount({ ...TBAccount, tokenContract: event.target.value as TBAccountParams["tokenContract"] })} value={TBAccount.tokenContract} /> setTBAccount({ ...TBAccount, tokenId: event.target.value })} value={TBAccount.tokenId} />
{/* ... other JSX elements */} ) } ``` -------------------------------- ### Sign Messages with Tokenbound SDK Source: https://docs.tokenbound.org/sdk/methods Generates an EIP-191 formatted signature for a given message. Supports various message formats including ASCII arrays, Uint8Arrays, and raw Uint8Arrays for viem compatibility. The signing is handled by the user's EOA wallet. ```javascript // Ethers 5 const arrayMessage: ArrayLike = [72, 101, 108, 108, 111] // "Hello" in ASCII // Ethers 5 or Ethers 6 const uint8ArrayMessage: Uint8Array = new Uint8Array([72, 101, 108, 108, 111]) // "Hello" in ASCII ``` ```javascript const signedMessage = await tokenboundClient.signMessage({ message: 'Ice cream so good', }) console.log(signedMessage) // Works in Ethers 5 or 6, throws in viem const signedUint8Message = await tokenboundClient.signMessage({ message: uint8ArrayMessage, }) console.log(signedUint8Message) // Works in viem const signedRawUint8Message = await tokenboundClient.signMessage({ message: { raw: uint8ArrayMessage }, }) console.log(signedUint8Message) ``` -------------------------------- ### Transfer ETH from TBA to Wallet Source: https://docs.tokenbound.org/guides/interact-with-tba This script transfers ETH from a deployed Tokenbound Account (TBA) back to the user's wallet. It requires the Tokenbound SDK client, wallet, provider, TBA address, and displayBalance function. The input is the amount of ETH to send, and the output includes the transaction details and updated balances. ```typescript // 3-transfer.ts import { formatEther, parseEther } from "ethers"; import { TBAccountParams } from "@tokenbound/sdk/dist/src/TokenboundClient"; import client, {wallet, provider, tokenBoundAccount, displayBalance} from "./client"; // transfer eth from B -> A (async () => { console.log(`wallet: ${wallet.address}`); await displayBalance(wallet.address); console.log(`TBA address: ${tokenBoundAccount}`) displayBalance(tokenBoundAccount) const amount = parseEther("1"); console.log(`sending ${formatEther(amount)} ETH from ${tokenBoundAccount} to ${wallet.address}`); const executedCall = await client.executeCall({ account: tokenBoundAccount, to: wallet.address as TBAccountParams["tokenContract"], value: amount, data: "", }); console.log("\n---\n",executedCall,"\n---\n"); await provider.waitForTransaction(executedCall); await displayBalance(wallet.address); await displayBalance(tokenBoundAccount); })() ``` -------------------------------- ### Transfer ETH from Wallet to TBA Source: https://docs.tokenbound.org/guides/interact-with-tba This script transfers ETH from the user's wallet to a Tokenbound Account (TBA). It requires the wallet, provider, TBA address, and a displayBalance function. The input is the amount of ETH to send, and the output is the updated balances of both accounts. ```typescript // 1-transfer.ts import { formatEther, parseEther } from "ethers"; import { wallet, provider, tokenBoundAccount, displayBalance } from "./client"; // transfer eth from Wallet -> TBA (async () => { console.log(`sender:`, wallet.address); await displayBalance(wallet.address); const amount = parseEther("1"); console.log(`sending ${formatEther(amount)} ETH from ${wallet.address} to ${tokenBoundAccount}`); await wallet.sendTransaction({ to: tokenBoundAccount, value: amount }) await displayBalance(wallet.address); await displayBalance(tokenBoundAccount); })() ``` -------------------------------- ### Display TBA State Data in React Source: https://docs.tokenbound.org/guides/read-a-tba This snippet renders the TBAccount and retrievedAccount state objects as formatted JSON within a pre tag. It also provides a reset button to clear the account state. ```tsx
    {JSON.stringify({...TBAccount, retrievedAccount}, null, 2)}
  
``` -------------------------------- ### Execute arbitrary contract calls with TokenboundClient Source: https://docs.tokenbound.org/sdk/methods Performs an arbitrary contract call from a Tokenbound account, allowing for actions like minting NFTs or interacting with DAOs. It replaces the deprecated executeCall method and returns a transaction hash. ```javascript const executedCall = await tokenboundClient.execute({ account: '', to: '', value: '', data: '', }) console.log(executedCall) ``` ```javascript const encodedMintFunctionData = encodeFunctionData({ abi: zora721.abi, functionName: 'purchase', args: [BigInt(zora721.quantity)], }) const mintToTBATxHash = await tokenboundClient.execute({ account: zora721.tbaAddress, to: zora721.proxyContractAddress, value: zora721.mintPrice * BigInt(zora721.quantity), data: encodedMintFunctionData, }) ``` -------------------------------- ### Configure NFT Metadata animation_url Source: https://docs.tokenbound.org/iframe Update your NFT metadata's animation_url field to point to the Tokenbound iFrame service. This allows marketplaces to render the Tokenbound account interface for specific NFTs. ```json { "animation_url": "https://iframe-tokenbound.vercel.app///" } ``` -------------------------------- ### transferETH Source: https://docs.tokenbound.org/sdk/methods Transfers ETH to a recipient from a Tokenbound account. ```APIDOC ## POST /transferETH ### Description Transfer ETH to a recipient from a Tokenbound account. ### Method POST ### Endpoint /transferETH ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **account** (string) - Required - The Tokenbound account address. - **amount** (number) - Required - Amount, in decimal form (eg. 0.01 ETH). - **recipientAddress** (string) - Required - The recipient address or ENS. - **chainId** (string) - Optional - The ID of the chain the transaction should be executed on. If supplied, this will send a cross-chain transaction from the TBA via a bridge. ### Request Example ```json { "account": "", "amount": 0.01, "recipientAddress": "" } ``` ### Response #### Success Response (200) - **transactionHash** (string) - The transaction hash of the transfer. #### Response Example ```json { "transactionHash": "0x..." } ``` ``` -------------------------------- ### Deconstruct Tokenbound Account Bytecode Source: https://docs.tokenbound.org/sdk/methods Deconstructs the bytecode of a Tokenbound account into its core components, including implementation address, salt, token ID, token contract, and chain ID. Returns a SegmentedERC6551Bytecode object or null if the account is not deployed. ```javascript const segmentedBytecode = await tokenboundClient.deconstructBytecode({ accountAddress: '', }) console.log(segmentedBytecode) ``` -------------------------------- ### Transfer ETH from a Tokenbound account Source: https://docs.tokenbound.org/sdk/methods Transfers a specified amount of ETH from a Tokenbound account to a recipient address. The amount is provided in decimal format. ```javascript const transferETH = await tokenboundClient.transferETH({ account: '', amount: 0.01, recipientAddress: '', }) console.log(transferETH) ``` -------------------------------- ### Validate signer authorization for Tokenbound accounts Source: https://docs.tokenbound.org/sdk/methods Checks if the current wallet client or signer has authorization to perform actions on behalf of a specific Tokenbound account. Returns a boolean indicating if the account is a valid signer. ```javascript const isValidSigner = await tokenboundClient.isValidSigner({ account: ZORA721_TBA_ADDRESS, }) console.log('isValidSigner?', isValidSigner) ``` -------------------------------- ### Transfer ERC-20 Tokens with Tokenbound Account Source: https://docs.tokenbound.org/sdk/methods Transfers ERC-20 tokens from a Tokenbound account to a specified recipient. Requires the tokenbound account address, recipient address, ERC-20 token address, and token decimals. Optionally, a chain ID can be provided for cross-chain transactions. ```javascript const transferERC20 = await tokenboundClient.transferERC20({ account: '', amount: 0.1, recipientAddress: '', erc20tokenAddress: '', erc20tokenDecimals: '', }) console.log(transferERC20) //... ``` -------------------------------- ### isValidSigner Source: https://docs.tokenbound.org/sdk/methods Checks if a tokenbound account has signing authorization, determining if the active WalletClient or Signer can sign transactions on behalf of the TBA. ```APIDOC ## GET /isValidSigner ### Description Checks if a tokenbound account has signing authorization. This determines whether the active `WalletClient` or `Signer` can be used to sign transactions on behalf of the TBA. ### Method GET ### Endpoint /isValidSigner ### Parameters #### Path Parameters None #### Query Parameters - **account** (string) - Required - The Tokenbound account address. #### Request Body None ### Request Example ```json { "account": "ZORA721_TBA_ADDRESS" } ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the account is a valid signer, otherwise false. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Transfer NFTs from a Tokenbound account Source: https://docs.tokenbound.org/sdk/methods Transfers an ERC721 or ERC1155 token from a Tokenbound account to a specified recipient address. Returns the transaction hash of the transfer. ```javascript const transferNFT = await tokenboundClient.transferNFT({ account: '', tokenType: 'ERC721', tokenContract: '', tokenId: '', recipientAddress: '', }) console.log(transferNFT) ``` -------------------------------- ### transferNFT Source: https://docs.tokenbound.org/sdk/methods Transfers an NFT (ERC721 or ERC1155) to a recipient from a Tokenbound account. ```APIDOC ## POST /transferNFT ### Description Transfer an NFT to a recipient from a Tokenbound account. ### Method POST ### Endpoint /transferNFT ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **account** (string) - Required - The Tokenbound account address. - **tokenType** (string) - Required - Token type: 'ERC721' or 'ERC1155'. - **tokenContract** (string) - Required - The address of the token contract. - **tokenId** (string) - Required - The tokenId of the NFT. - **recipientAddress** (string) - Required - The recipient address or ENS. - **amount** (number) - Optional - The number of tokens to send (1155 only). - **chainId** (string) - Optional - The ID of the chain the transaction should be executed on. If supplied, this will send a cross-chain transaction from the TBA via a bridge. ### Request Example ```json { "account": "", "tokenType": "ERC721", "tokenContract": "", "tokenId": "", "recipientAddress": "", "amount": 1 } ``` ### Response #### Success Response (200) - **transactionHash** (string) - The transaction hash of the transfer. #### Response Example ```json { "transactionHash": "0x..." } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.