-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroadcast-tx.js
More file actions
80 lines (70 loc) · 2.64 KB
/
broadcast-tx.js
File metadata and controls
80 lines (70 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Broadcast Zcash testnet transaction
const fetch = require('node-fetch');
const fs = require('fs');
async function broadcast() {
// Read from file
let txHex;
if (fs.existsSync('testnet-tx.hex')) {
txHex = fs.readFileSync('testnet-tx.hex', 'utf8').trim();
console.log('📂 Loaded transaction from testnet-tx.hex');
} else if (process.argv[2]) {
txHex = process.argv[2];
console.log('📋 Using transaction from command line');
} else {
console.error('❌ No transaction provided');
console.log('\nUsage:');
console.log(' node broadcast-tx.js [hex]');
console.log(' or create testnet-tx.hex file');
process.exit(1);
}
console.log('📤 Broadcasting transaction...');
console.log(' Size:', txHex.length / 2, 'bytes');
console.log(' First bytes:', txHex.slice(0, 32) + '...\n');
try {
// Try blockchair API
console.log('🌐 Using Blockchair API...');
const response = await fetch('https://api.blockchair.com/zcash/testnet/push/transaction', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `data=${txHex}`
});
const data = await response.json();
if (data.data && data.data.transaction_hash) {
const txid = data.data.transaction_hash;
console.log('✅ SUCCESS! Transaction broadcast');
console.log('');
console.log('━'.repeat(60));
console.log('🎉 TXID:', txid);
console.log('━'.repeat(60));
console.log('');
console.log('🔍 View on explorer:');
console.log(` https://blockexplorer.one/zcash/testnet/tx/${txid}`);
console.log('');
console.log('📝 SAVE THIS TXID FOR BOUNTY SUBMISSION!');
// Save TXID
fs.writeFileSync('testnet-txid.txt', txid);
console.log('💾 Saved to: testnet-txid.txt');
return txid;
} else {
throw new Error(data.context?.error || 'Unknown error from API');
}
} catch (error) {
console.error('❌ Broadcast failed:', error.message);
console.log('');
console.log('💡 Alternative methods:');
console.log('');
console.log('1. Use zcash-cli:');
console.log(` zcash-cli -testnet sendrawtransaction "${txHex}"`);
console.log('');
console.log('2. Use block explorer:');
console.log(' https://blockexplorer.one/zcash/testnet (Broadcast tab)');
console.log(' Paste the hex and submit');
console.log('');
console.log('3. If transaction is invalid, check:');
console.log(' - UTXO is not already spent');
console.log(' - Signature is correct');
console.log(' - Fee is sufficient');
process.exit(1);
}
}
broadcast().catch(console.error);