Transaction
The Transaction API in Coffer SDK provides comprehensive functionality for creating, managing, and monitoring Bitcoin transactions. It supports various transaction types, fee management, and multi-signature operations.
Create Transaction
Creating a Transaction
const txResult = await coffer.createTransaction({
originAddress: string; // Sender address
destinationAddresses: { // Recipient address list
address: string; // Recipient address
amount: number; // Amount (BTC)
}[];
asset: string; // Asset type
assetType: string; // Asset protocol type
networkType: BitcoinNetwork; // Network type (mainnet/testnet)
txFeeRate: number; // Transaction fee rate (sat/vB)
});
Return type
interface CreateTransactionResult {
id: string; // Transaction ID
}
Querying Transactions
// Get all transactions
const allTx = await coffer.fetchAllTransaction();
// Get unsigned transactions
const unsignedTx = await coffer.fetchUnsignedTransactions();
// Get signed transactions
const signedTx = await coffer.fetchSignedTransactions();
Querying Asset
// Get wallet asset balance
const balance = await coffer.getBalance();
// Return type
interface Assets {
asset: string;
assetType: string;
balances: number;
price: number;
name: string;
logo: string;
value: string;
networkType: string;
unconfirmedBalances?: string;
}
Advanced Features
Transaction Status
enum TransactionStatus {
Signing = "signing",
Signed = "signed",
Broadcasted = "broadcasted",
Completed = "completed"
}
Multi-signature Support
interface Transaction {
signedInfo: {
name: string;
action: "approved" | "rejected";
actionAt: number;
address: string;
}[];
signedStatus: {
M: number; // Required signatures
N: number; // Total signers
};
}
Error Handling
try {
await coffer.createTransaction(params);
} catch (error) {
if (error instanceof CofferError) {
console.error('Coffer error:', error.message, error.code);
} else {
console.error('Unknown error:', error);
}
}
Security Considerations
-
Origin Validation
- Ensure correct
origin
parameter setting
- Ensure correct
-
Transaction Validation
- Validate all input parameters before creating transactions
- Ensure amounts don't exceed available balance
- Verify recipient address format
-
Network Security
- Use HTTPS
- Implement appropriate retry mechanisms
- Handle network timeouts