Skip to content

Commit

Permalink
refactor: formatted documents and added prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanniegb committed Nov 22, 2024
1 parent 9bb3d73 commit 30eb0d7
Show file tree
Hide file tree
Showing 35 changed files with 1,623 additions and 615 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": false,
"trailingComma": "es5",
"semi": true,
"tabWidth": 2
}
80 changes: 49 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,47 @@ Packages
`src` - SDK client for all projects, signing enabled via Starknet.js.

## 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
Clone repository and install dependencies:

# clone the repo

```
git clone <repo>
```

# install dependencies

```
npm install
```

# build packages

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

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

### Standard configuration with WalletClient

To configure tokenbound using walletClient:

```js
Expand All @@ -70,28 +82,31 @@ const options = {
const tokenbound = new TokenboundClient(options)
```

### Standard configuration with Account signer
### 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';
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}`
}
jsonRPC: `https://starknet-mainnet.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}`,
};

const tokenbound = new TokenboundClient(options)
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
Expand All @@ -100,21 +115,22 @@ const deployAccount = async () => {
await tokenbound.createAccount({
tokenContract: tokenContract,
tokenId: tokenId,
salt: "3000000000"
})
salt: "3000000000",
});
} catch (error) {
console.log(error);
}
catch (error) {
console.log(error)
}
}
};
```

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`
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.
Expand All @@ -124,17 +140,19 @@ const getAccount = async () => {
const account = await tokenbound.getAccount({
tokenContract: tokenContract,
tokenId: tokenId,
salt: "3000000000"
})
}
salt: "3000000000",
});
};
```

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
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
Expand All @@ -144,15 +162,15 @@ const getDeploymentStatus = async () => {
const status = await tokenbound.checkAccountDeployment({
tokenContract,
tokenId,
salt: "3000000000"
})
setDeployStatus(status?.deployed)
setAccountClassHash(status?.classHash)
}
salt: "3000000000",
});
setDeployStatus(status?.deployed);
setAccountClassHash(status?.classHash);
};
```
Parameter Description Type
Parameter Description Type
- tokenContract: The token contract address
- tokenId: The token ID
- salt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.
You may also see any lint errors in the console.
10 changes: 5 additions & 5 deletions examples/sdk-starknetjs-starknetkit-starknet-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import './App.css';
import React from "react";
import "./App.css";
import StarknetProvider from "./components/StarknetProvider";
import Home from 'components/Home';
import Home from "components/Home";

function App() {
return (
<StarknetProvider>
< Home/>
<Home />
</StarknetProvider>
);
}

export default App;
export default App;
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import React from "react";
import { mainnet } from "@starknet-react/chains";
import { StarknetConfig, publicProvider, useInjectedConnectors, argent, braavos, starkscan } from "@starknet-react/core";
import {
StarknetConfig,
publicProvider,
useInjectedConnectors,
argent,
braavos,
starkscan,
} from "@starknet-react/core";

function StarknetProvider({ children }: any) {
const { connectors: injected } = useInjectedConnectors({
recommended: [argent(), braavos()],
includeRecommended: 'always',
})

const connectors = [
...injected,
]

return (
<StarknetConfig
connectors={connectors}
chains={[mainnet]}
provider={publicProvider()}
explorer={starkscan}
autoConnect
>
{children}
</StarknetConfig>
)
}
const { connectors: injected } = useInjectedConnectors({
recommended: [argent(), braavos()],
includeRecommended: "always",
});

export default StarknetProvider;
const connectors = [...injected];

return (
<StarknetConfig
connectors={connectors}
chains={[mainnet]}
provider={publicProvider()}
explorer={starkscan}
autoConnect
>
{children}
</StarknetConfig>
);
}

export default StarknetProvider;
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

body {
margin: 0;
padding: 0
padding: 0;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
}
10 changes: 5 additions & 5 deletions examples/sdk-starknetjs-starknetkit-starknet-react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";

const root = ReactDOM.createRoot(document.getElementById('root')!);
const root = ReactDOM.createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
extend: {},
},
plugins: [],
}
};
38 changes: 19 additions & 19 deletions examples/sdk-starknetjs-starknetkit-starknet-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ES2015",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"baseUrl": "./src",
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "dist"]
}
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ES2015",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"baseUrl": "./src"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "dist"]
}
2 changes: 1 addition & 1 deletion examples/sdk-starknetjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.
You may also see any lint errors in the console.
19 changes: 13 additions & 6 deletions examples/sdk-starknetjs/src/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";

interface FormatAddressProps {
address: string | undefined;
Expand All @@ -11,17 +11,24 @@ const FormatAddress: React.FC<FormatAddressProps> = ({ address }) => {

const copyToClipboard = (): void => {
navigator.clipboard.writeText(address ?? "");
alert('Address copied to clipboard!');
alert("Address copied to clipboard!");
};

return (
<div className='flex items-center gap-2'>
<span className='text-lg font-bold'> {shortenAddress(address ?? "")}</span>
<button className='bg-blue-400 text-xs py-2 text-white rounded-sm px-3' onClick={copyToClipboard} style={{ marginLeft: '10px' }}>
<div className="flex items-center gap-2">
<span className="text-lg font-bold">
{" "}
{shortenAddress(address ?? "")}
</span>
<button
className="bg-blue-400 text-xs py-2 text-white rounded-sm px-3"
onClick={copyToClipboard}
style={{ marginLeft: "10px" }}
>
Copy
</button>
</div>
);
};

export default FormatAddress;
export default FormatAddress;
Loading

0 comments on commit 30eb0d7

Please sign in to comment.