- REST API Endpoints
- Transaction Verification Service
- Chain-Specific Services
- Safe Transaction Service
- Types
- Utilities
GET /api/health
Check the health status of the service.
Response:
{
"success": true,
"status": "healthy",
"timestamp": "2024-01-01T00:00:00.000Z",
"environment": "production",
"version": "1.0.0"
}GET /api/chains
Returns all supported blockchain networks.
Response:
{
"success": true,
"data": {
"chains": [
{
"id": 1,
"name": "Ethereum Mainnet",
"nativeCurrency": {
"name": "Ethereum",
"symbol": "ETH",
"decimals": 18
},
"blockExplorerUrl": "https://etherscan.io",
"isActive": true
},
{
"id": 137,
"name": "Polygon",
"nativeCurrency": {
"name": "MATIC",
"symbol": "MATIC",
"decimals": 18
},
"blockExplorerUrl": "https://polygonscan.com",
"isActive": true
}
]
}
}GET /api/chains/:networkId
Returns configuration for a specific chain.
Parameters:
networkId(path): The chain/network ID
Response:
{
"success": true,
"data": {
"id": 1,
"name": "Ethereum Mainnet",
"nativeCurrency": {
"name": "Ethereum",
"symbol": "ETH",
"decimals": 18
},
"blockExplorerUrl": "https://etherscan.io",
"isActive": true
}
}Response (Not Found):
{
"success": false,
"error": "Chain not found: 999999",
"code": "CHAIN_NOT_FOUND"
}GET /api/chains/:networkId/transaction-url/:txHash
Returns the block explorer URL for a transaction.
Parameters:
networkId(path): The chain/network IDtxHash(path): Transaction hash
Response:
{
"success": true,
"data": {
"url": "https://etherscan.io/tx/0xabc123..."
}
}POST /api/verify
Verify a single transaction against expected parameters.
Verify a single transaction against expected parameters.
Request Body:
{
"txHash": "0xabc123...",
"networkId": 1,
"symbol": "ETH",
"fromAddress": "0x1234...",
"toAddress": "0x5678...",
"amount": 1.5,
"timestamp": 1234567890,
"isSwap": false,
"safeTxHash": "",
"nonce": 0,
"chainType": "EVM",
"importedFromDraftOrBackupService": false
}Response (Success):
{
"success": true,
"data": {
"status": "SUCCESS",
"transaction": {
"hash": "0xabc123...",
"from": "0x1234...",
"to": "0x5678...",
"amount": 1.5,
"timestamp": 1234567890
}
}
}Response (Validation Failed):
{
"success": true,
"data": {
"status": "FAILED",
"error": "Transaction amount does not match expected amount",
"errorCode": "AMOUNT_MISMATCH"
}
}Response (Error):
{
"success": false,
"error": "Validation failed",
"details": [
{
"field": "txHash",
"message": "txHash is required"
}
]
}POST /api/verify-batch
Verify multiple transactions in parallel (maximum 100 transactions).
Request Body:
{
"transactions": [
{
"txHash": "0xabc123...",
"networkId": 1,
"symbol": "ETH",
"fromAddress": "0x1234...",
"toAddress": "0x5678...",
"amount": 1.5,
"timestamp": 1234567890
},
{
"txHash": "0xdef456...",
"networkId": 137,
"symbol": "MATIC",
"fromAddress": "0x9abc...",
"toAddress": "0xdef0...",
"amount": 10.0,
"timestamp": 1234567890
}
]
}Response:
{
"success": true,
"data": {
"total": 2,
"successful": 2,
"failed": 0,
"results": [
{
"status": "SUCCESS",
"transaction": {
"hash": "0xabc123...",
"from": "0x1234...",
"to": "0x5678...",
"amount": 1.5,
"timestamp": 1234567890
}
},
{
"status": "SUCCESS",
"transaction": {
"hash": "0xdef456...",
"from": "0x9abc...",
"to": "0xdef0...",
"amount": 10.0,
"timestamp": 1234567890
}
}
]
}
}POST /api/timestamp
Get the timestamp of a transaction from the blockchain.
Request Body:
{
"txHash": "0xabc123...",
"networkId": 1
}Response:
{
"success": true,
"data": {
"txHash": "0xabc123...",
"networkId": 1,
"timestamp": 1234567890,
"date": "2009-02-13T23:31:30.000Z"
}
}POST /api/price
Get the current USD price of a token.
Request Body:
{
"networkId": 1,
"symbol": "ETH",
"tokenAddress": null
}For ERC-20 tokens, provide the contract address:
{
"networkId": 1,
"symbol": "USDC",
"tokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
}Response:
{
"success": true,
"data": {
"networkId": 1,
"symbol": "ETH",
"tokenAddress": null,
"priceUsd": 2345.67
}
}Note: If the price cannot be fetched, priceUsd returns 0 instead of an error.
The main service for verifying blockchain transactions across multiple chains.
Verifies a transaction against expected parameters.
Parameters:
interface TransactionDetailInput {
txHash: string; // Transaction hash
symbol: string; // Token symbol (ETH, SOL, etc.)
networkId: number; // Network ID
fromAddress: string; // Expected sender address
toAddress: string; // Expected recipient address
amount: number; // Expected amount
timestamp: number; // Transaction timestamp (Unix)
safeTxHash?: string; // Safe transaction hash (optional)
nonce?: number; // Transaction nonce (optional)
chainType?: ChainType; // Chain type override (optional)
isSwap?: boolean; // Is swap transaction (optional)
importedFromDraftOrBackupService?: boolean; // Skip timestamp validation
}Returns:
interface TransactionValidationResult {
isValid: boolean;
transaction?: NetworkTransactionInfo;
error?: string;
errorCode?: BlockchainErrorCode;
}Example:
const result = await transactionVerificationService.verifyTransaction({
txHash: '0xabc123...',
networkId: 1,
symbol: 'ETH',
fromAddress: '0x1234...',
toAddress: '0x5678...',
amount: 1.5,
timestamp: Date.now() / 1000,
});
if (result.isValid) {
console.log('Valid transaction:', result.transaction);
}Verifies multiple transactions in parallel.
Parameters:
inputs: Array of transaction detail inputs
Returns:
- Array of validation results
Example:
const results = await transactionVerificationService.verifyTransactions([
{ txHash: '0x123...', networkId: 1, ... },
{ txHash: '0x456...', networkId: 137, ... },
]);Gets the Unix timestamp of a transaction.
Parameters:
txHash: Transaction hashnetworkId: Network ID
Returns:
- Unix timestamp (seconds)
The service supports verifying donations made through donation handler contracts (batch donation contracts). When a transaction is made to a known donation handler contract, the service automatically:
- Detects that the transaction is to a donation handler
- Parses event logs from the transaction (Transfer events for ERC-20, DonationMade events for native tokens)
- Finds the specific transfer matching the expected recipient address
- Extracts the correct amount for that specific donation
| Method | Description |
|---|---|
donateManyERC20 |
Batch ERC-20 token donations to multiple recipients |
donateManyEth |
Batch native token (ETH/MATIC/etc.) donations to multiple recipients |
| Network | Contract Address |
|---|---|
| Polygon | 0x4102E15f4621Fc45fCe8E07442A702BD49fcea4b |
| Polygon (legacy verification only) | 0x6e349C56F512cB4250276BF36335c8dd618944A1 |
For transactions like this Polygon example, where a single transaction distributes tokens to multiple recipients:
- The
donateManyERC20function is called on the donation handler contract - The handler distributes tokens to multiple recipients in one transaction
- When verifying, the service parses all Transfer events
- It finds the transfer matching the
toAddressfrom the verification input - The amount and from address are extracted from that specific transfer
For native token batch donations:
- The
donateManyEthfunction is called with native value (ETH/MATIC) - The handler distributes native tokens to multiple recipients
- When verifying, the service parses
DonationMadeevents from the logs - It finds the donation matching the
toAddressfrom the verification input - The amount is extracted and the network's native currency symbol is used
To add support for new donation handler contracts, update the configuration in src/config/donationHandlers.ts:
export const DONATION_HANDLER_ADDRESSES: Record<number, string[]> = {
[NetworkId.POLYGON]: [
'0x4102E15f4621Fc45fCe8E07442A702BD49fcea4b', // Active handler
'0x6e349C56F512cB4250276BF36335c8dd618944A1', // Legacy handler, no longer used by FE
'0xNEW_HANDLER_ADDRESS', // Add new handlers here
],
[NetworkId.MAINNET]: [
'0xMAINNET_HANDLER_ADDRESS', // Add mainnet handlers
],
};Handles Ethereum Virtual Machine compatible blockchains.
Fetches transaction details from an EVM chain.
Gets transaction timestamp from block.
Validates that a swap transaction transfers tokens to the target address.
Example:
import { evmTransactionService } from '@giveth/blockchain-integration-service';
const txInfo = await evmTransactionService.getTransactionInfo({
txHash: '0x123...',
networkId: 1,
symbol: 'ETH',
fromAddress: '0xabc...',
toAddress: '0xdef...',
amount: 1.0,
timestamp: Date.now() / 1000,
});Handles Solana blockchain transactions.
Fetches transaction details from Solana.
Example:
import { solanaTransactionService } from '@giveth/blockchain-integration-service';
const txInfo = await solanaTransactionService.getTransactionInfo({
txHash: '5J7Qu...',
networkId: 101,
symbol: 'SOL',
fromAddress: 'Donor123...',
toAddress: 'Project456...',
amount: 5.0,
timestamp: Date.now() / 1000,
});Handles Gnosis Safe multisig transactions.
Fetches the actual blockchain transaction hash from a Safe transaction.
Parameters:
safeMessageHash: Safe transaction hashnetworkId: Network ID
Returns:
- Transaction hash or null if not executed
Checks if a Safe transaction has been executed.
getSafeTransactionDetails(safeMessageHash: string, networkId: number): Promise<Record<string, unknown>>
Gets detailed information about a Safe transaction.
Example:
import { safeTransactionService } from '@giveth/blockchain-integration-service';
// Fetch actual tx hash from Safe
const txHash = await safeTransactionService.fetchSafeTransactionHash(
'0xsafe123...',
1
);
// Check execution status
const isExecuted = await safeTransactionService.isSafeTransactionExecuted(
'0xsafe123...',
1
);Configuration for a supported chain, used in API responses:
interface ChainConfig {
id: number;
name: string;
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
blockExplorerUrl: string;
isActive: boolean;
}enum ChainType {
EVM = 'EVM',
SOLANA = 'SOLANA',
}Result format for transaction verification API responses:
interface TransactionVerificationResult {
status: TransactionStatus;
transaction?: {
hash: string;
from: string;
to: string;
amount: number;
timestamp: number;
};
error?: string;
errorCode?: string;
}enum TransactionStatus {
SUCCESS = 'SUCCESS',
FAILED = 'FAILED',
PENDING = 'PENDING',
NOT_FOUND = 'NOT_FOUND',
}interface NetworkTransactionInfo {
hash: string;
amount: number;
nonce?: number;
from: string;
to: string;
currency: string;
timestamp: number;
status: TransactionStatus;
blockNumber?: number;
gasUsed?: string;
gasPrice?: string;
}enum BlockchainErrorCode {
TRANSACTION_NOT_FOUND = 'TRANSACTION_NOT_FOUND',
TRANSACTION_FAILED = 'TRANSACTION_FAILED',
INVALID_NETWORK_ID = 'INVALID_NETWORK_ID',
INVALID_TRANSACTION_HASH = 'INVALID_TRANSACTION_HASH',
FROM_ADDRESS_MISMATCH = 'FROM_ADDRESS_MISMATCH',
TO_ADDRESS_MISMATCH = 'TO_ADDRESS_MISMATCH',
AMOUNT_MISMATCH = 'AMOUNT_MISMATCH',
TIMESTAMP_TOO_OLD = 'TIMESTAMP_TOO_OLD',
NONCE_ALREADY_USED = 'NONCE_ALREADY_USED',
NETWORK_ERROR = 'NETWORK_ERROR',
PROVIDER_ERROR = 'PROVIDER_ERROR',
SWAP_VALIDATION_FAILED = 'SWAP_VALIDATION_FAILED',
SAFE_TRANSACTION_NOT_FOUND = 'SAFE_TRANSACTION_NOT_FOUND',
UNSUPPORTED_CHAIN = 'UNSUPPORTED_CHAIN',
}Compares two numbers with a margin of error.
Parameters:
a: First numberb: Second numberdelta: Margin of error (default: 0.001)
Validates Ethereum address format.
Validates EVM transaction hash format.
Validates Solana address format.
Validates Solana transaction signature.
Normalizes address to lowercase for comparison.
isTimestampValid(txTimestamp: number, donationTimestamp: number, thresholdSeconds?: number): boolean
Checks if timestamp is within acceptable range.
debug(message: string, meta?: unknown): voidinfo(message: string, meta?: unknown): voidwarn(message: string, meta?: unknown): voiderror(message: string, meta?: unknown): voidfatal(message: string, meta?: unknown): void
Example:
import { logger } from '@giveth/blockchain-integration-service';
logger.info('Transaction verified', { txHash: '0x123...' });
logger.error('Verification failed', { error: 'Amount mismatch' });