transactions.get()
Retrieve a specific transaction by its unique identifier.
Signature
transactions.get(id: string): Promise<Transaction>Parameters
id
- Type:
string - Required: Yes
- Format: UUID
The unique identifier of the transaction.
Returns
- Type:
Promise<Transaction>
interface Transaction {
id: string;
piid?: string | null;
payer: string;
pay_to: string;
amount: string;
asset: string;
entry_id?: string | null;
transaction_hash: string;
created_at: number;
}Usage
Basic Example
const tx = await grapevine.transactions.get('tx_456e7890-e89b-12d3-a456-426614174111');
console.log('Transaction details:');
console.log(' Payer:', tx.payer);
console.log(' Recipient:', tx.pay_to);
console.log(' Amount:', formatUSDC(tx.amount));
console.log(' Asset:', tx.asset);
console.log(' Date:', new Date(tx.created_at * 1000).toLocaleString());Transaction Detail View
async function getTransactionDetails(txId: string) {
const tx = await grapevine.transactions.get(txId);
// Get wallet info for payer and recipient
const [payer, recipient] = await Promise.all([
grapevine.wallets.getByAddress(tx.payer),
grapevine.wallets.getByAddress(tx.pay_to)
]);
// Get entry info if available
let entry = null;
if (tx.entry_id) {
// Need feed ID - might need to look up differently
// This is simplified
entry = { id: tx.entry_id };
}
return {
id: tx.id,
amount: formatUSDC(tx.amount),
asset: tx.asset,
payer: {
address: tx.payer,
username: payer.username
},
recipient: {
address: tx.pay_to,
username: recipient.username
},
entry,
blockchainHash: tx.transaction_hash,
explorerUrl: `https://basescan.org/tx/${tx.transaction_hash}`,
date: new Date(tx.created_at * 1000)
};
}
function formatUSDC(weiAmount: string): string {
const usdc = Number(BigInt(weiAmount)) / 1e6;
return `${usdc.toFixed(2)}`;
}Verify Transaction
async function verifyTransaction(txId: string, expectedAmount: string) {
try {
const tx = await grapevine.transactions.get(txId);
const matches = tx.amount === expectedAmount;
return {
exists: true,
verified: matches,
transaction: tx
};
} catch (error) {
if (error.message.includes('404')) {
return { exists: false, verified: false };
}
throw error;
}
}Error Handling
try {
const tx = await grapevine.transactions.get(txId);
console.log('Transaction found:', tx);
} catch (error) {
if (error.message.includes('404')) {
console.error('Transaction not found');
} else if (error.message.includes('400')) {
console.error('Invalid transaction ID format');
} else {
console.error('Error:', error.message);
}
}Notes
- Authentication: Not required - public endpoint
- ID Format: Must be a valid UUID
- Alternative: Use getByHash() if you have the blockchain transaction hash
Related
- transactions.getByHash() - Get by blockchain hash
- transactions.list() - List transactions
- API: Get Transaction - REST API reference