@@ -7,73 +7,89 @@ import { parseUnits, getAddress } from 'viem'
77import { useCallback , useEffect } from 'react'
88import { 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
1612const recipientAddress = getAddress ( '0x9FefE8a875E7a9b0574751E191a2AF205828dEA4' )
17- const ethAmount = 0.05
13+ const ethAmount = 0.005
1814const ethAmountWei = parseUnits ( `${ ethAmount } ` , 18 )
1915
16+ const TOKEN_CONTRACT = `0x26c55c8d83d657b2fc1df497f0c991e3612bc6b2`
17+ const TOKEN_ID = '5'
18+
2019export 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 </ >
0 commit comments