Skip to content

Commit

Permalink
Merge pull request #72 from tokenbound/bj/maintenance-bump-viem
Browse files Browse the repository at this point in the history
Maintenance: Version bump viem, update examples
  • Loading branch information
bjfresh authored Oct 22, 2024
2 parents 83449aa + ab5e851 commit 6244f1e
Show file tree
Hide file tree
Showing 103 changed files with 9,137 additions and 9,626 deletions.
15 changes: 0 additions & 15 deletions .eslintrc.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ dist-ssr
/broadcast
/cache
/out
/.vscode
2 changes: 1 addition & 1 deletion .husky/pre-push
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
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

19 changes: 0 additions & 19 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ VITE_PRIVATE_ALCHEMY_API_KEY=REPLACE_WITH_YOUR_ALCHEMY_API_KEY

# PUBLIC ENV VARS, add to `.env`:
VITE_ANVIL_MAINNET_FORK_ENDPOINT=https://eth-mainnet.alchemyapi.io/v2/$VITE_PRIVATE_ALCHEMY_API_KEY
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=19869786
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=21023556
```

2. Build the SDK from `/packages/sdk`
Expand Down
38 changes: 38 additions & 0 deletions biome.json
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"
}
}
}
7 changes: 7 additions & 0 deletions examples/vite-wagmi-ethers-rainbowkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# vite-wagmi-ethers-rainbowkit

## 0.0.7

### Patch Changes

- Updated dependencies
- @tokenbound/sdk@0.5.5

## 0.0.6

### Patch Changes
Expand Down
15 changes: 9 additions & 6 deletions examples/vite-wagmi-ethers-rainbowkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-wagmi-ethers-rainbowkit",
"version": "0.0.6",
"version": "0.0.7",
"private": true,
"scripts": {
"dev": "vite",
Expand All @@ -10,17 +10,20 @@
},
"dependencies": {
"@tokenbound/sdk": "workspace:^",
"@wagmi/core": "^2.13.9",
"buffer": "^6.0.3",
"@rainbow-me/rainbowkit": "^1.0.11",
"@tanstack/react-query": "^5.59.15",
"@rainbow-me/rainbowkit": "^2.2.0",
"ethers": "^5.7.2",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"util": "^0.12.5",
"viem": "^2.10.5",
"wagmi": "^2.3.1"
"viem": "^2.21.32",
"wagmi": "^2.12.20"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.0.4",
Expand Down
4 changes: 2 additions & 2 deletions examples/vite-wagmi-ethers-rainbowkit/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'buffer'
import process from 'process'
import { Buffer } from 'node:buffer'
import process from 'node:process'

window.global = window
window.process = process
Expand Down
214 changes: 114 additions & 100 deletions examples/vite-wagmi-ethers-rainbowkit/src/App.tsx
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>
)}
</>
)
}
Loading

0 comments on commit 6244f1e

Please sign in to comment.