Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kkailiwang/980935d4b5987355929a8040acd50d56 to your computer and use it in GitHub Desktop.

Select an option

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
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