-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from tokenbound/bj/maintenance-bump-viem
Maintenance: Version bump viem, update examples
- Loading branch information
Showing
103 changed files
with
9,137 additions
and
9,626 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ dist-ssr | |
/broadcast | ||
/cache | ||
/out | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm lint-staged | ||
# pnpm lint:fix |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", | ||
"files": { | ||
"ignore": [ | ||
"node_modules/*", | ||
"dist/**/*" | ||
] | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"formatWithErrors": false, | ||
"indentStyle": "tab", | ||
"lineWidth": 80 | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"correctness": { | ||
"noUnusedImports": "error" | ||
}, | ||
"suspicious": { | ||
"noArrayIndexKey": "off", | ||
"noExplicitAny": "off" | ||
} | ||
} | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"trailingCommas": "all", | ||
"semicolons": "asNeeded", | ||
"arrowParentheses": "always" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,122 @@ | ||
import { ConnectButton } from '@rainbow-me/rainbowkit' | ||
import { useAccount } from 'wagmi' | ||
import { TokenboundClient } from '@tokenbound/sdk' | ||
import { ConnectButton } from "@rainbow-me/rainbowkit" | ||
import { useAccount } from "wagmi" | ||
import { TokenboundClient } from "@tokenbound/sdk" | ||
|
||
import { Account } from './components' | ||
import { Account } from "./components" | ||
|
||
import { parseUnits, getAddress } from 'viem' | ||
import { useCallback, useEffect } from 'react' | ||
import { useEthersSigner } from './hooks' | ||
import { parseUnits, getAddress } from "viem" | ||
import { useCallback, useEffect } from "react" | ||
import { useEthersSigner } from "./hooks" | ||
|
||
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5 | ||
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract | ||
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4') | ||
// Origin NFT: MoonTrees #0 on Base Sepolia | ||
const originNFT = { | ||
tokenContract: getAddress("0xcf7ea35b7421a8ff2ff460a939e294ac13a05342"), | ||
tokenId: "0", | ||
} | ||
|
||
// TBA: Tokenbound Account derived from MoonTrees #0 on Base Sepolia | ||
const sendingTBA = getAddress("0x5F50CAf6244d10C32965354F8c4d84D84503D42D") | ||
const recipientAddress = getAddress( | ||
"0x9FefE8a875E7a9b0574751E191a2AF205828dEA4", | ||
) | ||
const ethAmount = 0.005 | ||
const ethAmountWei = parseUnits(`${ethAmount}`, 18) | ||
|
||
export function App() { | ||
const { isConnected, address } = useAccount() | ||
const signer = useEthersSigner({ chainId: 5 }) | ||
// or useSigner() from legacy wagmi versions: const { data: signer } = useSigner() | ||
|
||
const tokenboundClient = new TokenboundClient({ signer, chainId: 5 }) | ||
|
||
useEffect(() => { | ||
async function testTokenboundClass() { | ||
const account = await tokenboundClient.getAccount({ | ||
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb', | ||
tokenId: '9', | ||
}) | ||
|
||
const preparedExecution = await tokenboundClient.prepareExecution({ | ||
account: account, | ||
to: account, | ||
value: 0n, | ||
data: '', | ||
}) | ||
|
||
const preparedAccount = await tokenboundClient.prepareCreateAccount({ | ||
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb', | ||
tokenId: '1', | ||
}) | ||
|
||
console.log('getAccount', account) | ||
console.log('preparedExecution', preparedExecution) | ||
console.log('preparedAccount', preparedAccount) | ||
|
||
// if (signer) { | ||
// signer?.sendTransaction(preparedAccount) | ||
// signer?.sendTransaction(preparedExecuteCall) | ||
// } | ||
} | ||
|
||
testTokenboundClass() | ||
}, [tokenboundClient]) | ||
|
||
const createAccount = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const createdAccount = await tokenboundClient.createAccount({ | ||
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb', | ||
tokenId: '1', | ||
}) | ||
alert(`new account: ${createdAccount}`) | ||
}, [tokenboundClient]) | ||
|
||
const execute = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const executedCall = await tokenboundClient.execute({ | ||
account: sendingTBA, | ||
to: recipientAddress, | ||
value: ethAmountWei, | ||
data: '0x', | ||
}) | ||
executedCall && alert(`Executed: ${executedCall}`) | ||
}, [tokenboundClient]) | ||
|
||
const transferETH = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const executedTransfer = await tokenboundClient.transferETH({ | ||
account: sendingTBA, | ||
recipientAddress, | ||
amount: ethAmount, | ||
}) | ||
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`) | ||
}, [tokenboundClient]) | ||
|
||
return ( | ||
<> | ||
<h1>Ethers 5 Signer + RainbowKit + Vite</h1> | ||
<ConnectButton /> | ||
{isConnected && <Account />} | ||
{address && ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '8px', | ||
margin: '32px 0 0', | ||
maxWidth: '320px', | ||
}} | ||
> | ||
<button onClick={() => execute()}>EXECUTE CALL</button> | ||
<button onClick={() => createAccount()}>CREATE ACCOUNT</button> | ||
<button onClick={() => transferETH()}>TRANSFER ETH</button> | ||
</div> | ||
)} | ||
</> | ||
) | ||
const { isConnected, address } = useAccount() | ||
const signer = useEthersSigner({ chainId: 5 }) | ||
// or useSigner() from legacy wagmi versions: const { data: signer } = useSigner() | ||
|
||
const tokenboundClient = new TokenboundClient({ signer, chainId: 5 }) | ||
|
||
useEffect(() => { | ||
async function testTokenboundClass() { | ||
const account = tokenboundClient.getAccount({ | ||
tokenContract: originNFT.tokenContract, | ||
tokenId: originNFT.tokenId, | ||
}) | ||
|
||
const preparedExecution = await tokenboundClient.prepareExecution({ | ||
account: account, | ||
to: account, | ||
value: 0n, | ||
data: "", | ||
}) | ||
|
||
const preparedAccount = await tokenboundClient.prepareCreateAccount({ | ||
tokenContract: "0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb", | ||
tokenId: "1", | ||
}) | ||
|
||
console.log("getAccount", account) | ||
console.log("preparedExecution", preparedExecution) | ||
console.log("preparedAccount", preparedAccount) | ||
|
||
// if (signer) { | ||
// signer?.sendTransaction(preparedAccount) | ||
// signer?.sendTransaction(preparedExecuteCall) | ||
// } | ||
} | ||
|
||
testTokenboundClass() | ||
}, [tokenboundClient]) | ||
|
||
const createAccount = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const createdAccount = await tokenboundClient.createAccount({ | ||
tokenContract: "0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb", | ||
tokenId: "1", | ||
}) | ||
alert(`new account: ${createdAccount}`) | ||
}, [tokenboundClient, address]) | ||
|
||
const execute = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const executedCall = await tokenboundClient.execute({ | ||
account: sendingTBA, | ||
to: recipientAddress, | ||
value: ethAmountWei, | ||
data: "0x", | ||
}) | ||
executedCall && alert(`Executed: ${executedCall}`) | ||
}, [tokenboundClient, address]) | ||
|
||
const transferETH = useCallback(async () => { | ||
if (!tokenboundClient || !address) return | ||
const executedTransfer = await tokenboundClient.transferETH({ | ||
account: sendingTBA, | ||
recipientAddress, | ||
amount: ethAmount, | ||
}) | ||
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`) | ||
}, [tokenboundClient, address]) | ||
|
||
return ( | ||
<> | ||
<h1>Ethers 5 Signer + RainbowKit + Vite</h1> | ||
<ConnectButton /> | ||
{isConnected && <Account />} | ||
{address && ( | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "8px", | ||
margin: "32px 0 0", | ||
maxWidth: "320px", | ||
}} | ||
> | ||
<button type="button" onClick={() => execute()}> | ||
EXECUTE | ||
</button> | ||
<button type="button" onClick={() => createAccount()}> | ||
CREATE ACCOUNT | ||
</button> | ||
<button type="button" onClick={() => transferETH()}> | ||
TRANSFER ETH | ||
</button> | ||
</div> | ||
)} | ||
</> | ||
) | ||
} |
Oops, something went wrong.