Skip to content

Commit a0221ec

Browse files
authored
Merge pull request #45 from tokenbound/bj/fp-26-handling-executecall-vs-execute-with-interface-check
SDK implementation of V3
2 parents 08f20e6 + 84255eb commit a0221ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3945
-7062
lines changed

.changeset/tame-socks-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tokenbound/sdk': minor
3+
---
4+
5+
Integrate V3 registry and account implementation into SDK

.github/workflows/on-create-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
run: cd packages/sdk
3131

3232
- name: Install dependencies
33-
run: npm install
33+
run: cd packages/sdk && npm install
3434

3535
- name: Clean install and build 🔧
36-
run: npm ci && npm run build
36+
run: cd packages/sdk && npm ci && npm run build
3737
# run: pnpm ci && pnpm build // pnpm ci not yet implemented: https://github.com/pnpm/pnpm/issues/6100
3838

3939
- name: Publish package on NPM 📦
40-
run: npm publish
40+
run: cd packages/sdk && npm publish
4141
env:
42-
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
42+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

README.md

Lines changed: 200 additions & 117 deletions
Large diffs are not rendered by default.

examples/vite-wagmi-ethers-rainbowkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.16.2",
21-
"wagmi": "^1.4.3"
20+
"viem": "^1.17.1",
21+
"wagmi": "^1.4.5"
2222
},
2323
"devDependencies": {
2424
"@types/react": "^18.2.21",

examples/vite-wagmi-ethers-rainbowkit/src/App.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import { parseUnits, getAddress } from 'viem'
88
import { useCallback, useEffect } from 'react'
99
import { useEthersSigner } from './hooks'
1010

11-
// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
12-
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
13-
// const ethAmount = 0.1
14-
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)
15-
16-
const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
11+
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
12+
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
1713
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
18-
const ethAmount = 0.05
14+
const ethAmount = 0.005
1915
const ethAmountWei = parseUnits(`${ethAmount}`, 18)
2016

2117
export function App() {
@@ -32,7 +28,7 @@ export function App() {
3228
tokenId: '9',
3329
})
3430

35-
const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
31+
const preparedExecution = await tokenboundClient.prepareExecution({
3632
account: account,
3733
to: account,
3834
value: 0n,
@@ -45,7 +41,7 @@ export function App() {
4541
})
4642

4743
console.log('getAccount', account)
48-
console.log('prepareExecuteCall', preparedExecuteCall)
44+
console.log('preparedExecution', preparedExecution)
4945
console.log('preparedAccount', preparedAccount)
5046

5147
// if (signer) {
@@ -66,15 +62,25 @@ export function App() {
6662
alert(`new account: ${createdAccount}`)
6763
}, [tokenboundClient])
6864

69-
const executeCall = useCallback(async () => {
65+
const execute = useCallback(async () => {
7066
if (!tokenboundClient || !address) return
71-
const executedCall = await tokenboundClient.executeCall({
67+
const executedCall = await tokenboundClient.execute({
7268
account: sendingTBA,
7369
to: recipientAddress,
7470
value: ethAmountWei,
7571
data: '0x',
7672
})
77-
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
73+
executedCall && alert(`Executed: ${executedCall}`)
74+
}, [tokenboundClient])
75+
76+
const transferETH = useCallback(async () => {
77+
if (!tokenboundClient || !address) return
78+
const executedTransfer = await tokenboundClient.transferETH({
79+
account: sendingTBA,
80+
recipientAddress,
81+
amount: ethAmount,
82+
})
83+
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
7884
}, [tokenboundClient])
7985

8086
return (
@@ -92,8 +98,9 @@ export function App() {
9298
maxWidth: '320px',
9399
}}
94100
>
95-
<button onClick={() => executeCall()}>EXECUTE CALL</button>
101+
<button onClick={() => execute()}>EXECUTE CALL</button>
96102
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
103+
<button onClick={() => transferETH()}>TRANSFER ETH</button>
97104
</div>
98105
)}
99106
</>

examples/vite-wagmi-ethers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.16.2",
21-
"wagmi": "^1.4.3"
20+
"viem": "^1.17.1",
21+
"wagmi": "^1.4.5"
2222
},
2323
"devDependencies": {
2424
"@types/react": "^18.2.21",

examples/vite-wagmi-ethers/src/App.tsx

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,89 @@ import { parseUnits, getAddress } from 'viem'
77
import { useCallback, useEffect } from 'react'
88
import { useEthersSigner } from './hooks'
99

10-
// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
11-
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
12-
// const ethAmount = 0.1
13-
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)
14-
15-
const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
10+
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
11+
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
1612
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
17-
const ethAmount = 0.05
13+
const ethAmount = 0.005
1814
const ethAmountWei = parseUnits(`${ethAmount}`, 18)
1915

16+
const TOKEN_CONTRACT = `0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2`
17+
const TOKEN_ID = '5'
18+
2019
export function App() {
2120
const { isConnected, address } = useAccount()
2221
const signer = useEthersSigner({ chainId: 5 })
2322
// or useSigner() from legacy wagmi versions: const { data: signer } = useSigner()
2423

25-
const tokenboundClient = new TokenboundClient({ signer, chainId: 5 })
24+
const tokenboundClient = new TokenboundClient({
25+
signer,
26+
chainId: 5,
27+
})
2628

2729
useEffect(() => {
30+
console.log('signer', signer)
2831
async function testTokenboundClass() {
29-
const account = await tokenboundClient.getAccount({
30-
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
31-
tokenId: '9',
32+
if (!tokenboundClient) return
33+
34+
const tokenboundAccount = tokenboundClient.getAccount({
35+
tokenContract: TOKEN_CONTRACT,
36+
tokenId: TOKEN_ID,
3237
})
3338

34-
const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
35-
account: account,
36-
to: account,
39+
const preparedExecution = await tokenboundClient.prepareExecution({
40+
account: tokenboundAccount,
41+
to: recipientAddress,
3742
value: 0n,
3843
data: '',
3944
})
4045

41-
const preparedAccount = await tokenboundClient.prepareCreateAccount({
42-
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
43-
tokenId: '1',
46+
const preparedCreateAccount = await tokenboundClient.prepareCreateAccount({
47+
tokenContract: TOKEN_CONTRACT,
48+
tokenId: TOKEN_ID,
4449
})
4550

46-
console.log('getAccount', account)
47-
console.log('prepareExecuteCall', preparedExecuteCall)
48-
console.log('preparedAccount', preparedAccount)
51+
console.log('getAccount', tokenboundAccount)
52+
console.log('preparedExecuteCall', preparedExecution)
53+
console.log('preparedAccount', preparedCreateAccount)
4954

50-
// if (signer) {
51-
// signer?.sendTransaction(preparedAccount)
52-
// signer?.sendTransaction(preparedExecuteCall)
55+
// if (address) {
56+
// walletClient?.sendTransaction(preparedCreateAccount)
57+
// walletClient?.sendTransaction(preparedExecuteCall)
5358
// }
5459
}
5560

5661
testTokenboundClass()
57-
}, [tokenboundClient])
62+
}, [])
5863

5964
const createAccount = useCallback(async () => {
6065
if (!tokenboundClient || !address) return
6166
const createdAccount = await tokenboundClient.createAccount({
62-
tokenContract: '0xe7134a029cd2fd55f678d6809e64d0b6a0caddcb',
63-
tokenId: '1',
67+
tokenContract: TOKEN_CONTRACT,
68+
tokenId: TOKEN_ID,
6469
})
70+
console.log(`new account: ${createdAccount}`)
6571
alert(`new account: ${createdAccount}`)
6672
}, [tokenboundClient])
6773

68-
const executeCall = useCallback(async () => {
74+
const execute = useCallback(async () => {
6975
if (!tokenboundClient || !address) return
70-
const executedCall = await tokenboundClient.executeCall({
76+
const executedCall = await tokenboundClient.execute({
7177
account: sendingTBA,
7278
to: recipientAddress,
7379
value: ethAmountWei,
7480
data: '0x',
7581
})
76-
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
82+
executedCall && alert(`Executed: ${executedCall}`)
83+
}, [tokenboundClient])
84+
85+
const transferETH = useCallback(async () => {
86+
if (!tokenboundClient || !address) return
87+
const executedTransfer = await tokenboundClient.transferETH({
88+
account: sendingTBA,
89+
recipientAddress,
90+
amount: ethAmount,
91+
})
92+
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
7793
}, [tokenboundClient])
7894

7995
return (
@@ -91,8 +107,9 @@ export function App() {
91107
maxWidth: '320px',
92108
}}
93109
>
94-
<button onClick={() => executeCall()}>EXECUTE CALL</button>
110+
<button onClick={() => execute()}>EXECUTE</button>
95111
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
112+
<button onClick={() => transferETH()}>TRANSFER ETH</button>
96113
</div>
97114
)}
98115
</>

examples/vite-wagmi-ethers6/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.16.2",
21-
"wagmi": "^1.4.3"
20+
"viem": "^1.17.1",
21+
"wagmi": "^1.4.5"
2222
},
2323
"devDependencies": {
2424
"@types/react": "^18.2.21",

examples/vite-wagmi-ethers6/src/App.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import { parseUnits, getAddress } from 'viem'
88
import { useCallback, useEffect } from 'react'
99
import { useEthers6Signer } from './hooks'
1010

11-
// const sendingTBA = '0x33D622b211C399912eC0feaaf1caFD01AFA53980'
12-
// const recipientAddress = getAddress('0x5ed25DCC8490809215cd0632492467BEbc60B8d5')
13-
// const ethAmount = 0.1
14-
// const ethAmountWei = parseUnits(`${ethAmount}`, 18)
15-
16-
const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1'
11+
// const sendingTBA = '0x047A2F5c8C97948675786e9a1A12EB172CF802a1' // Sapienz #5 on Goerli w/ V2 contract: https://tokenbound.org/assets/goerli/0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2/5
12+
const sendingTBA = '0xa2221cc0f5012D60d0bF91B840A4Ef990D44Ae39' // Sapienz #5 on Goerli w/ V3 contract
1713
const recipientAddress = getAddress('0x9FefE8a875E7a9b0574751E191a2AF205828dEA4')
18-
const ethAmount = 0.05
14+
const ethAmount = 0.005
1915
const ethAmountWei = parseUnits(`${ethAmount}`, 18)
2016

2117
export function App() {
@@ -34,7 +30,7 @@ export function App() {
3430
tokenId: '9',
3531
})
3632

37-
const preparedExecuteCall = await tokenboundClient.prepareExecuteCall({
33+
const preparedExecution = await tokenboundClient.prepareExecution({
3834
account: account,
3935
to: account,
4036
value: 0n,
@@ -47,7 +43,7 @@ export function App() {
4743
})
4844

4945
console.log('getAccount', account)
50-
console.log('prepareExecuteCall', preparedExecuteCall)
46+
console.log('preparedExecution', preparedExecution)
5147
console.log('preparedAccount', preparedAccount)
5248

5349
// if (signer) {
@@ -68,15 +64,25 @@ export function App() {
6864
alert(`new account: ${createdAccount}`)
6965
}, [tokenboundClient])
7066

71-
const executeCall = useCallback(async () => {
67+
const execute = useCallback(async () => {
7268
if (!tokenboundClient || !address) return
73-
const executedCall = await tokenboundClient.executeCall({
69+
const executedCall = await tokenboundClient.execute({
7470
account: sendingTBA,
7571
to: recipientAddress,
7672
value: ethAmountWei,
7773
data: '0x',
7874
})
79-
executedCall && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
75+
executedCall && alert(`Executed: ${executedCall}`)
76+
}, [tokenboundClient])
77+
78+
const transferETH = useCallback(async () => {
79+
if (!tokenboundClient || !address) return
80+
const executedTransfer = await tokenboundClient.transferETH({
81+
account: sendingTBA,
82+
recipientAddress,
83+
amount: ethAmount,
84+
})
85+
executedTransfer && alert(`Sent ${ethAmount} ETH to ${recipientAddress}`)
8086
}, [tokenboundClient])
8187

8288
return (
@@ -94,8 +100,9 @@ export function App() {
94100
maxWidth: '320px',
95101
}}
96102
>
97-
<button onClick={() => executeCall()}>EXECUTE CALL</button>
103+
<button onClick={() => execute()}>EXECUTE CALL</button>
98104
<button onClick={() => createAccount()}>CREATE ACCOUNT</button>
105+
<button onClick={() => transferETH()}>TRANSFER ETH</button>
99106
</div>
100107
)}
101108
</>

examples/vite-wagmi-viem/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.16.2",
21-
"wagmi": "^1.4.3"
20+
"viem": "^1.17.1",
21+
"wagmi": "^1.4.5"
2222
},
2323
"devDependencies": {
2424
"@types/react": "^18.2.21",

0 commit comments

Comments
 (0)