# API Reference

## Standard configuration

### `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.

```typescript
import { TokenboundClient, Call, TBAVersion, TBAChainID } from "starknet-tokenbound-sdk";
import { useAccount, useConnect } from "@starknet-react/core";

    const { connect, connectors } = useConnect();
    const { account } = useAccount()
    
    // chain_id: starknet-mainnet
    const options:WalletClient = {
      account: account,
      version: TBAVersion.V3,
      chain_id: TBAChainID.mainnet,
      jsonRPC: `https://starknet-mainnet.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_API_KEY}`
    }
    
    // chain_id: starknet-sepolia
    const options = {
      account: account,
      version: TBAVersion.V3,
      chain_id: TBAChainID.sepolia,
      jsonRPC: `https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/${process.env.REACT_APP_ALCHEMY_API_KEY}`,
    };
    
    let tokenbound: any;
    if (account) {
      tokenbound = new TokenboundClient(options);
    }
```

## Deploy Tokenbound Account

```typescript
let tokenbound: any;
if (account) {
  tokenbound = new TokenboundClient(options);
}

const deployAccount = async () => {
  try {
    await tokenbound.createAccount({
      tokenContract: '<token_contract_address>',
      tokenId: '<token_id>',
      salt: '<arbitary number>'
    });
  } catch (error) {
    console.log(error);
  }
};
```

## Get Tokenbound Account

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

```typescript
 let tokenbound: any;
if (account) {
  tokenbound = new TokenboundClient(options);
}

const getAccount = async () => {
  const account = await tokenbound.getAccount({
    tokenContract: '<token_contract_address>',
    tokenId: '<token_id>',
    salt: `arbitrary number`>
  });
  setTBAAccount(num.toHex(account));
};

console.log(getAccount) //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.&#x20;

<pre class="language-typescript"><code class="lang-typescript">  await tokenbound.createAccount({
     tokenContract: `&#x3C;tokenContract>`,
<strong>     tokenId: `&#x3C;token_id>`,
</strong>     salt: `arbitrary number`>
  });
</code></pre>

| Parameter         | Description                                                 | Type   |
| ----------------- | ----------------------------------------------------------- | ------ |
| **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.

```typescript
const account = await tokenbound.getAccount({
     tokenContract: `<tokenContract>`,
     tokenId: `<token_id>`,
     salt: `arbitrary number`>
});    
```

<table><thead><tr><th width="221.33333333333334">Parameter</th><th>Description</th><th>Type</th></tr></thead><tbody><tr><td><strong>tokenContract</strong></td><td>The address of the token contract.</td><td>string</td></tr><tr><td><strong>tokenId</strong></td><td>The token ID.</td><td>string</td></tr><tr><td><strong>salt</strong></td><td>The salt used when the account was created (optional)</td><td>string</td></tr></tbody></table>

### `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.

```typescript
await tokenbound.checkAccountDeployment({
   tokenContract:`<tokenContract>`,
   tokenId:<`token_id`>,
   salt: `<arbitrary number`
}); 
```

| Parameter     | Description                                           | Type   |
| ------------- | ----------------------------------------------------- | ------ |
| 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`

**Returns** the address of the tokenbound owner.&#x20;

```typescript
const nftowner = await tokenbound.getOwner({
    tbaAddress: `<tokenbound_contract_address`>
});
console.log(nftowner)
```

<table><thead><tr><th>Parameter</th><th width="178.33333333333334">Description</th><th>Type</th></tr></thead><tbody><tr><td>tbaAddress</td><td>The tokenbound address</td><td>string</td></tr></tbody></table>

### `getOwnerNFT`

Extracts information about the original 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

```typescript
const nftowner = await tokenbound.getOwnerNFT(tbaAddress)
console.log(nftowner);
```

<table><thead><tr><th>Parameter</th><th width="178.33333333333334">Description</th><th>Type</th></tr></thead><tbody><tr><td><strong>tbaAddress</strong></td><td>The Tokenbound account address</td><td>string</td></tr></tbody></table>

### `transferNFT`

Transfer an NFT to a recipient from a Tokenbound account.

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

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

| Parameter           | Description                        | Type   |
| ------------------- | ---------------------------------- | ------ |
| **tbaAddress**      | The Tokenbound account             | string |
| **tokenID**         | The tokenId fo the NFT             | string |
| **contractAddress** | The address of the token contract. | string |
| **sender**          | The TBA sending 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

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

| Parameter           | Description                     | Type   |
| ------------------- | ------------------------------- | ------ |
| 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).

```typescript
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])
  }
```

<table><thead><tr><th>Parameter</th><th width="228.33333333333334">Description</th><th>Type</th></tr></thead><tbody><tr><td><strong>account</strong></td><td>The Tokenbound account address.</td><td>string</td></tr><tr><td>[call] </td><td>array of payload</td><td>Call</td></tr></tbody></table>

### `lock`

Locks a tokenbound account.

<pre class="language-typescript"><code class="lang-typescript"><strong>  await tokenbound.lock({
</strong>     tbaAddress: `&#x3C;tokenbound_address>`,
     lockUntill: 1728057939
  });
</code></pre>

| Paramter   | description                               | type   |
| ---------- | ----------------------------------------- | ------ |
| tbaAddress | The Tokenbound account address            | string |
| lockUntill | amount of time to lock tokenbound account | number |

### `isLocked`

Returns an array of bool and uint256 which references the lock status of the tokenbound and time left until unlock.

```typescript
 const isLocked = await tokenbound.isLocked({
      tbaAddress: `<tokenbound_address>`,
 });
```

| Paramter   | description                    | type   |
| ---------- | ------------------------------ | ------ |
| tbaAddress | The Tokenbound account address | string |

### `upgrade`

This is used to upgrade a Tokenbound account by updating the class hash of the contract.

```typescript
  await tokenbound.upgrade({
    newClassHash: "0x0000000000........0000",
    tbaAddress: `<tokenbound_address>`,
  });
```

| Paramter     | description                       | type   |
| ------------ | --------------------------------- | ------ |
| newClassHash | The class hash to be upgraded to. | string |
| tbaAddress   | The Tokenbound account address    | string |

### `setPermission`

This allows you to assign or revoke specific permissions for different addresses on a Tokenbound account.

```typescript
 await tokenbound.setPermission({
    tbaAddress: `<tokenbound_address>`,
    permissionedAddresses: [`<addresses>`],
    permissions: [true]
  });
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tbaexplorer.com/sdk/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
