transactions.getByHash()
Retrieve a transaction by its blockchain transaction hash.
Signature
transactions.getByHash(hash: string): Promise<Transaction>Parameters
hash
- Type:
string - Required: Yes
- Format: Ethereum transaction hash (0x-prefixed, 66 characters)
The blockchain transaction hash.
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.getByHash(
'0xabc123def456789abc123def456789abc123def456789abc123def456789abcd'
);
console.log('Transaction found:');
console.log(' ID:', tx.id);
console.log(' Payer:', tx.payer);
console.log(' Recipient:', tx.pay_to);
console.log(' Amount:', formatUSDC(tx.amount));Verify On-Chain Payment
async function verifyOnChainPayment(txHash: string) {
try {
const tx = await grapevine.transactions.getByHash(txHash);
return {
verified: true,
platformTxId: tx.id,
amount: formatUSDC(tx.amount),
asset: tx.asset,
payer: tx.payer,
recipient: tx.pay_to,
entry: tx.entry_id,
timestamp: new Date(tx.created_at * 1000)
};
} catch (error) {
if (error.message.includes('404')) {
return {
verified: false,
error: 'Transaction not found in Grapevine system'
};
}
throw error;
}
}
// Usage
const result = await verifyOnChainPayment('0xabc123...');
if (result.verified) {
console.log(`Payment of ${result.amount} verified!`);
} else {
console.log('Payment not found');
}Link Blockchain to Platform
async function getGrapevineTransaction(blockchainTxHash: string) {
const tx = await grapevine.transactions.getByHash(blockchainTxHash);
// Now we have the Grapevine transaction ID
// Can use this to link to entry, feeds, etc.
if (tx.entry_id) {
console.log('Payment was for entry:', tx.entry_id);
}
return tx;
}Explorer Integration
function getExplorerLinks(tx: Transaction, network: 'testnet' | 'mainnet') {
const baseUrl = network === 'mainnet'
? 'https://basescan.org'
: 'https://sepolia.basescan.org';
return {
transaction: `${baseUrl}/tx/${tx.transaction_hash}`,
payer: `${baseUrl}/address/${tx.payer}`,
recipient: `${baseUrl}/address/${tx.pay_to}`
};
}
// Usage
const tx = await grapevine.transactions.getByHash(txHash);
const links = getExplorerLinks(tx, 'testnet');
console.log('View on explorer:', links.transaction);Error Handling
try {
const tx = await grapevine.transactions.getByHash(hash);
console.log('Transaction found:', tx);
} catch (error) {
if (error.message.includes('404')) {
console.error('Transaction not found - may not be a Grapevine payment');
} else if (error.message.includes('400')) {
console.error('Invalid hash format - must be 0x followed by 64 hex characters');
} else {
console.error('Error:', error.message);
}
}Notes
- Authentication: Not required - public endpoint
- Hash Format: Must be a valid Ethereum transaction hash (66 chars including 0x)
- Use Case: Useful when you have a blockchain transaction and want to find the corresponding Grapevine record
- Not Found: If the hash doesn't correspond to a Grapevine payment, returns 404
Related
- transactions.get() - Get by Grapevine ID
- transactions.list() - List transactions
- API: Get Transaction by Hash - REST API reference