Signing Transactions
signTransactions
import { useWallet } from '@txnlab/use-wallet-react'
import algosdk from 'algosdk'
function SendTransaction() {
const {
activeAddress,
signTransactions,
algodClient
} = useWallet()
const handleSend = async () => {
if (!activeAddress) return
try {
// Create transaction
const suggestedParams = await algodClient.getTransactionParams().do()
const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
sender: activeAddress,
receiver: activeAddress,
amount: 0,
suggestedParams
})
// Sign transaction
const signedTxns = await signTransactions([transaction])
// Send transaction
const { txid } = await algodClient.sendRawTransaction(signedTxns).do()
// Wait for confirmation
const result = await algosdk.waitForConfirmation(algodClient, txid, 4)
console.log(`Transaction confirmed at round ${result['confirmed-round']}`)
} catch (error) {
console.error('Error:', error)
}
}
return (
<button onClick={handleSend}>Send Transaction</button>
)
}transactionSigner
With Atomic Transaction Composer
With AlgoKit Utils
Last updated