Usage
const {
recordSendTransactionAsync,
data,
isLoading,
error
} = useRecordSendTransaction();
Parameters
The hook accepts an object with:
params (RecordSendTransactionParams):
transactionHash (string): The hash of the transaction to record
chain (Chain): The blockchain network (e.g., "STARKNET")
expectedSender (string): The expected sender wallet address
expectedRecipient (string): The expected recipient wallet address
expectedToken (ChainToken): The expected token (e.g., "USDC")
expectedAmount (string): The expected transaction amount
bearerToken (string): Bearer token for authentication
Return Value
Returns an object containing:
recordSendTransaction: Function to record transaction (fire-and-forget)
recordSendTransactionAsync: Promise-based function that resolves with the transaction record
data: The recorded transaction data (Transaction | undefined)
isLoading: Boolean indicating if the operation is in progress
isError: Boolean indicating if an error occurred
error: Error instance when isError is true, otherwise null
isSuccess: Boolean indicating if the recording completed successfully
reset: Function to reset the mutation state
Example Implementation
import { useRecordSendTransaction } from "@chipi-stack/chipi-react";
import type { Chain, ChainToken } from "@chipi-stack/chipi-expo";
export function RecordTransactionForm() {
const { recordSendTransactionAsync, data, isLoading, isError, error } = useRecordSendTransaction();
const { getToken } = useAuth();
const handleRecordTransaction = async () => {
try {
const token = await getToken();
if (!token) throw new Error("No token found");
// After a transfer, record the transaction
const transactionHash = "0x..."; // From your transfer transaction
const senderWallet = { publicKey: "0x123..." };
const merchant = "0x456...";
const amountUsd = "100.00";
await recordSendTransactionAsync({
params: {
transactionHash,
chain: "STARKNET" as Chain,
expectedSender: senderWallet.publicKey,
expectedRecipient: merchant,
expectedToken: "USDC" as ChainToken,
expectedAmount: amountUsd,
},
bearerToken: token,
});
} catch (err) {
console.error('Recording transaction failed:', err);
}
};
return (
<div className="bg-white rounded-xl shadow-lg p-6">
<h2 className="text-2xl font-bold mb-4">Record Transaction</h2>
<button
onClick={handleRecordTransaction}
disabled={isLoading}
className="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 disabled:bg-gray-400"
>
{isLoading ? 'Recording...' : 'Record Transaction'}
</button>
{data && (
<div className="mt-4 p-3 bg-gray-50 rounded-md">
<p className="text-sm font-mono break-all">
Transaction Recorded: {data.id}
</p>
</div>
)}
{isError && error && (
<div className="mt-4 p-3 bg-red-50 text-red-700 rounded-md">
Error: {error.message}
</div>
)}
</div>
);
}
Security Considerations
- Always verify recipient addresses
- Use encrypted private keys
- Implement proper PIN validation
- Monitor transaction status
Error Handling
- Handle insufficient token balance
- Validate wallet addresses
- Monitor gas fees
- Implement retry logic for failed transactions
Always verify recipient addresses. Transfers on StarkNet are irreversible.
- Approve - Required before transferring new token types
- Stake - For staking tokens