API Reference

TokenboundClient


The TokenboundClient class provides an interface for interacting with tokenbound accounts, enabling operations like account creation, transaction execution, token transfers (including ERC-721, ERC-1155, and ERC-20 tokens), and message signing.

The client is instantiated with an object containing one parameter:

Parameter

one of account or walletClient

mandatory

Standard configuration


import { TokenboundClient,WalletClient,Call } from "starknet-tokenbound-sdk"
import { useAccount } from "@starknet-react/core";

  const { account } = useAccount()

 const options:WalletClient = {
    account: account,
    registryAddress: `registry address`,
    implementationAddress: `implementation address`,
    jsonRPC: `https://starknet-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_API_KEY}`
  }

  let tokenboundClient: any;

  if (account) {
    tokenbound = new TokenboundClient(options)
  }

Making your first call

Now you can use the TokenboundClient to interact with the Tokenbound contracts:



const tokenboundClient = new TokenboundClient(options)
 
const tokenboundAccount = tokenboundClient.getAccount({
  tokenContract: '<token_contract_address>',
  tokenId: '<token_id>',
  salt:'<arbitary number>' // optional
})
 
console.log(tokenboundAccount) //0x1a2...3b4cd

TokenboundClient SDK Methods

The TokenboundClient enables the creation of and interaction with Tokenbound accounts:

createAccount


Creates a tokenbound account for an NFT. The deterministic address is calculated using the deploy_syscall with listed parameters alongside the implementation address. createAccount adds the account to the registry and initializes it for use.

await tokenbound.createAccount({
        tokenContract: `<tokenContract>`,
        tokenId: `<token_id>`,
        salt: `arbitrary number`>
      })
    }
ParameterDescriptionType

tokenContract

The address of the token contract.

string

tokenId

The token ID.

string

salt

The salt used to create a unique account address (optional)

number

getAccount

Gets the tokenbound account address for an NFT.

Returns the tokenbound account address for a given token contract and token ID.

 const account = await tokenbound.getAccount({
        tokenContract: `<tokenContract>`,
        tokenId: `<token_id>`,
        salt: `<arbitrary_value>`
      })
ParameterDescriptionType

tokenContract

The address of the token contract.

string

tokenId

The token ID.

string

salt

The salt used when the account was created (optional)

string

checkAccountDeployment

Check if the tokenbound account address has been activated using createAccount.

Returns a boolean indicating if a tokenbound account has been deployed (created) at the accountAddress and classHash of the contract

 const status = await tokenbound.checkAccountDeployment({
        tokenContract:`<tokenContract>`,
        tokenId:<`token_id`>,
        salt: `<arbitrary number` //optional
      })
      
ParameterDescriptionType

tokenContract

The address of the token contract.

string

tokenId

The token ID

string

salt

The salt used when the account was created (optional)

number


getOwner

Extracts information about the Tokenbound owner that is paired with the tokenbound.

Returns the address of the tokenbound owner.

const nftowner = await tokenbound.getOwner({tokenContract: `<tokenContract>`,tokenId: `<token_id>`,tbaAddress: `<tokenbound_contract_address`>})
console.log(nftowner)
ParameterDescriptionType

tokenContract

The Tokenbound account address.

string

tokenId

The token ID

string

tbaAddress

The tokenbound address

string

getOwnerNFT

Extracts information about the origin NFT that is paired with the tokenbound account.

Returns a Promise that resolves to a TokenboundAccountNFT object. The TokenboundAccountNFT object contains the following properties:

  • tokenContract: The token contract address

  • tokenId: The token ID

const nftowner = await tokenbound.getOwnerNFT(account as string)
console.log(nftowner);
ParameterDescriptionType

account

The Tokenbound account address

string

transferNFT


Transfer an NFT to a recipient from a Tokenbound account

Returns a Promise that resolves to the transaction hash of the transfer

await tokenbound.transferNFT({
          tbaAddress: `<tokenbound_address>`,
          contractAddress: `<tokenContract address>`,
          tokenId: <`token_id>`,
          sender: <`sender_address`>,
          recipient:`<recipeint_address>`
        })
ParameterDescriptionType

tbaAddress

The Tokenbound account

string

tokenID

The tokenId fo the NFT

string

contractAddress

The address of the token contract.

string

sender

The sender of the NFT

string

recipient

The recipient address

string



transferERC20


Transfer ERC-20 tokens to a recipient from a Tokenbound account

Returns a Promise that resolves to the transaction hash of the transfer

 await tokenbound.transferERC20({
        tbaAddress: `<tokenbound_address>`,
        contractAddress: `<erc20_token_address>`,
        recipient: `<recipient address>`,
        amount: "100000000000000000"
      })
ParameterDescriptionType

tbaAddress

The Tokenbound account address.

string

amount

Amount (eg. 0.1 USDC).

string

recipient

The recipient address

string

contractAddress

The ERC-20 token address.

string

execute

Execute a contract call on any arbitrary contract and engage in multi-contract interaction within a single transaction (multicall).

import { Call } from 'starknet-tokenbound-sdk';

  const call1: Call = {
      to: `<contractAddress>`, //contractAddress to call
      selector: `<selector>`, // method to be called on the contract
      calldata: [] // payload to be passed alongside the selector
    }
 const call2: Call = {
      to: `<contractAddress>`, //contractAddress to call
      selector: `<selector>`, // method to be called on the contract
      calldata: [] // payload to be passed alongside the selector
    }
    try {
      await tokenbound.execute(account as string, [call1, call2])
    }
ParameterDescriptionType

account

The Tokenbound account address.

string

[call]

array of payload

Call

lock

Lock a tokenbound account


await tokenbound.lock({tbaAddress: account as string,duration_in_sec: 300})}

Paramterdescriptiontype

account

The Tokenbound account address

string

duration_in_sec

amount of time to lock tokenbound account

number

is_locked

Returns an array of bool and uint256 which references the lock status of the tokenbound and time

    const lockStatus = await tokenbound.is_locked(account as string)
Paramterdescriptiontype

account

The Tokenbound account address

string

Last updated