Skip to content

Commit

Permalink
Merge pull request #50 from horuslabsio/v3
Browse files Browse the repository at this point in the history
chore: tba v3 implementation
  • Loading branch information
Darlington02 authored Oct 8, 2024
2 parents 4792151 + 5b16aae commit 7c1a1ec
Show file tree
Hide file tree
Showing 95 changed files with 2,713 additions and 36,018 deletions.
149 changes: 127 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,147 @@
</a>
</p>

## Available SDKs
# Tokenbound SDK

### developmentKit
Houses the Tokenbound SDK, a front-end library for interacting with tokenbound accounts on Starknet. The SDK 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.
This repo houses the Tokenbound SDK, a front-end library for interacting with ERC-6551 accounts on Starknet. The SDK 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. Any onchain action you can perform with your EOA wallet can be done with your NFT's Tokenbound account.

### connectorKit
Houses the Tokenbound Connectkit.
Packages
`src` - SDK client for all projects, signing enabled via Starknet.js.

The Tokenbound Connectkit enables users connect to existing Starknet dApps with their Tokenbound accounts.
## Examples
- `examples/sdk-starknetjs` - An example app using the tokenbound SDK in a react project with starknetjs
- `examples/sdk-starknetjs-starknetkit-starknet-react` - An example app using the tokenbound SDK in a react project with starknetjs, starknetkit and starknet-react

## Development
1. Clone repository
Development
Clone repository and install dependencies:
# clone the repo
```
git clone git@github.com:horuslabsio/TBA-SDK.git
git clone <repo>
```

2. Navigate into the SDK folder you intend to work on
# install dependencies
```
cd connectorKit
cd developmentKit
npm install
```

3. Install dependencies
# build packages
```
npm install
npm run build
```
NOTE: Any local changes to SDK methods in `TokenboundClient.ts` require a rebuild to be useable in the example apps in /example

## 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 two parameters:

#### Parameter
One of `account <AccountInterface>` or `walletClient <WalletClient>` is mandatory.

4. To build your SDK for publishing to NPM:
### Standard configuration with WalletClient
To configure tokenbound using walletClient:

```js
import { TokenboundClient, WalletClient } from 'starknet-tokenbound-sdk';

const walletClient: WalletClient = {
address: "0x0617D13Db952a2965580ebAc9DF602debFa12d0eAFB7c1a79D9dA03321169286",
privateKey: process.env.REACT_APP_PRIVATE_KEY!,
}

const options = {
walletClient: walletClient,
registryAddress: registryAddress,
implementationAddress: implementationAddress,
jsonRPC: `https://starknet-mainnet.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}`

}

const tokenbound = new TokenboundClient(options)
```
npm run build

### Standard configuration with Account signer
Refer to the starknet-react documentation, for notes on configuring your StarknetProvider.

```js
import { useAccount, useConnect } from '@starknet-react/core';

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

const tokenbound = new TokenboundClient(options)
```

For easy reference, we've prepared code examples for a few simple SDK interactions.

## TokenboundClient SDK Methods
The `TokenboundClient` enables creation of and interaction with Tokenbound accounts:

### createAccount
Creates a tokenbound account for an NFT. createAccount adds the account to the registry and initializes it for use. Prior to account creation, the address can already receive assets. Deploying the account allows the NFT's owner to interact with the account.

```js
const deployAccount = async () => {
try {
await tokenbound.createAccount({
tokenContract: tokenContract,
tokenId: tokenId,
salt: "3000000000"
})
}
catch (error) {
console.log(error)
}
}
```

5. To publish the SDK:
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.

```js
const getAccount = async () => {
const account = await tokenbound.getAccount({
tokenContract: tokenContract,
tokenId: tokenId,
salt: "3000000000"
})
}
```
npm run publish

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

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

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

```js
const getDeploymentStatus = async () => {
const status = await tokenbound.checkAccountDeployment({
tokenContract,
tokenId,
salt: "3000000000"
})
setDeployStatus(status?.deployed)
setAccountClassHash(status?.classHash)
}
```
## API Reference
Please check the individual SDK folders.
Parameter Description Type
- tokenContract: The token contract address
- tokenId: The token ID
- salt
25 changes: 0 additions & 25 deletions connectorKit/.gitignore

This file was deleted.

44 changes: 0 additions & 44 deletions connectorKit/Readme.md

This file was deleted.

13 changes: 0 additions & 13 deletions connectorKit/index.html

This file was deleted.

Loading

0 comments on commit 7c1a1ec

Please sign in to comment.