Created
March 19, 2026 23:12
-
-
Save kkailiwang/980935d4b5987355929a8040acd50d56 to your computer and use it in GitHub Desktop.
Send a Tempo AA (0x76) transaction using Privy React SDK's secp256k1_sign + viem tempoActions
This file contains hidden or 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
| import {useWallets} from '@privy-io/react-auth'; | |
| import { | |
| createWalletClient, | |
| custom, | |
| keccak256, | |
| padHex, | |
| parseSignature, | |
| serializeTransaction, | |
| stringToHex | |
| } from 'viem'; | |
| import {toAccount} from 'viem/accounts'; | |
| import {tempo} from 'viem/chains'; | |
| import {tempoActions} from 'viem/tempo'; | |
| const usdc = '0x20c000000000000000000000b9537d11c60e8b50'; | |
| function TempoAATransfer() { | |
| const {wallets} = useWallets(); | |
| const handleTransfer = async () => { | |
| const wallet = wallets[0]; | |
| const provider = await wallet.getEthereumProvider(); | |
| const account = toAccount({ | |
| address: wallet.address as `0x${string}`, | |
| async sign({hash}) { | |
| return provider.request({method: 'secp256k1_sign', params: [hash]}); | |
| }, | |
| async signMessage() { | |
| throw new Error('Not implemented'); | |
| }, | |
| async signTypedData() { | |
| throw new Error('Not implemented'); | |
| }, | |
| async signTransaction(transaction, {serializer = serializeTransaction} = {}) { | |
| const unsignedBytes = await serializer(transaction); | |
| const hash = keccak256(unsignedBytes); | |
| const signature = await provider.request({ | |
| method: 'secp256k1_sign', | |
| params: [hash] | |
| }); | |
| return serializer(transaction, parseSignature(signature)); | |
| } | |
| }); | |
| const walletClient = createWalletClient({ | |
| account, | |
| chain: tempo, | |
| transport: custom(provider) | |
| }).extend(tempoActions()); | |
| const receipt = await walletClient.token.transferSync({ | |
| to: wallet.address as `0x${string}`, | |
| amount: 1n, | |
| token: usdc, | |
| memo: padHex(stringToHex('Hello, world!'), {size: 32}), | |
| feeToken: usdc | |
| }); | |
| console.log('Receipt:', receipt); | |
| }; | |
| return <button onClick={handleTransfer}>Send Tempo AA Transfer</button>; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment