[2026-07-29T20:02:12.528] [INFO] ZEC - [broadcast] http://127.0.0.1:13341 0400008085202f8902379c0bdaf632fd33db128e09d668968227b58692bea6d9dbfc543d1a0f3ddd7b000000006b4830450221009a0bea8bdda456d703134399f597e20bc69fa3269a0d82f36d09ee932e40b3f5022070ec672315409a8ff9f44794049811b3c61c9ddd3009d8fe4be5f6a71ead9f7b0121030cc9463c102a09238c93a0214e0ab58111c3e8b1ade8dda203edfb632d36120cffffffff379c0bdaf632fd33db128e09d668968227b58692bea6d9dbfc543d1a0f3ddd7b010000006a47304402205a0b6ded765d1a89ff3139743c49d84f32155bd32ec1903e73560e408eb2b34f022057fc1f80b6ee55f34157146eff346dd9a3fdb4f90476153e7fb26f0c7504bebd0121030cc9463c102a09238c93a0214e0ab58111c3e8b1ade8dda203edfb632d36120cffffffff02a0860100000000001976a91483b62ff15ffd23e53fe8e551d11e9fad1ef1e7cf88acd0dd0600000000001976a9140222fa13d983610bcddcaf83e23f7ab7e092fc0288ac00000000000000000000000000000000000000 {"jsonrpc":"1.0","id":"curltest","result":null,"error":{"code":-1,"message":"the transaction will be rejected from the mempool until the next chain tip block: transaction did not pass consensus validation: could not convert an asynchronous verification error: downcast to known transaction error type failed, original error: ScriptInvalid"}}
router.post('/transfer', async (req, res) => {
const { utxos, destination, changeAddress, changeAmount } = req.body;
const toAddresses = JSON.stringify(destination);
try {
logger.info([transfer] ${toAddresses} ${changeAddress} ${changeAmount});
if (!Array.isArray(destination) || !Array.isArray(utxos) || !changeAddress) {
throw new Error("Invalid destination or utxos format");
}
checkUtxos(utxos);
const outputUtxos = buildOutputs(destination, changeAddress, changeAmount);
const inputUtxos = buildInputs(utxos);
const net = networks.zcash;
//messagePrefix不影响签名和上链,只是为了匹配zel网络参数,可以不修改
if (name === "ZEL") {
net.messagePrefix = "\u0018ZelCash Signed Message:\n"
}
const builder = new ZcashTransactionBuilder(net);
builder.setVersion(Number(version));
builder.setVersionGroupId(parseInt(versionGroupId, 16));
builder.setConsensusBranchId(parseInt(consensusBranchId, 16));
for (const inputItem of inputUtxos) {
builder.addInput(inputItem.hash,
inputItem.index,
ZcashTransaction.DEFAULT_SEQUENCE,
address.toOutputScript(inputItem.address, net),
inputItem.value);
}
for (const outputItem of outputUtxos) {
builder.addOutput(outputItem.address, outputItem.value);
}
logger.info([transfer] ${toAddresses} ${changeAmount} unsignedTx: ${JSON.stringify(builder)});
inputUtxos.forEach((input, index) => {
const keyPair = ECPair.fromWIF(input.wif);
if (keyPair) {
builder.sign({
vin: index,
keyPair: keyPair,
prevOutScriptType: 'p2pkh',
hashType: ZcashTransaction.SIGHASH_ALL
});
} else {
throw new Error(keyPair not found for input at index ${index} ${input.address});
}
});
// 完成所有输入的签名
const signedTransaction = builder.build();
const rawTx = signedTransaction.toHex();
logger.info([transfer] ${toAddresses} ${changeAmount} rawTx: ${rawTx});
const response = await broadcast(rawTx);
if (response && response.result) {
logger.info([transfer] ${toAddresses} txHash: ${response.result});
res.json({ code: 200, result: response.result, rawTx });
return;
}
throw new Error(response);
} catch (e) {
logger.error([transfer] failed ${toAddresses}, e);
res.json({
code: -1, msg: (e.message || e)
});
}
});
const zcash = {
"name": "ZEC",
"port": "8000",
"dustValue": "5000",
"version": 4,
"versionGroupId": "0x892f2085",
"logDir": "zec",
//{"code":-26,"message":"16: old-consensus-branch-id (Expected 4dec4df0, found c8e71055)"}
// https://github.com/zcash/zcash/blob/master/src/consensus/upgrades.cpp#L58
//https://github.com/zcash/zcash/blob/master/src/consensus/upgrades.cpp#L63
"consensusBranchId": "0x5437f330",
"nodes": [
{
"url": "http://127.0.0.1:13341",
"username": "mxctest",
"password": "testqweasd"
}
]
};
[2026-07-29T20:02:12.528] [INFO] ZEC - [broadcast] http://127.0.0.1:13341 0400008085202f8902379c0bdaf632fd33db128e09d668968227b58692bea6d9dbfc543d1a0f3ddd7b000000006b4830450221009a0bea8bdda456d703134399f597e20bc69fa3269a0d82f36d09ee932e40b3f5022070ec672315409a8ff9f44794049811b3c61c9ddd3009d8fe4be5f6a71ead9f7b0121030cc9463c102a09238c93a0214e0ab58111c3e8b1ade8dda203edfb632d36120cffffffff379c0bdaf632fd33db128e09d668968227b58692bea6d9dbfc543d1a0f3ddd7b010000006a47304402205a0b6ded765d1a89ff3139743c49d84f32155bd32ec1903e73560e408eb2b34f022057fc1f80b6ee55f34157146eff346dd9a3fdb4f90476153e7fb26f0c7504bebd0121030cc9463c102a09238c93a0214e0ab58111c3e8b1ade8dda203edfb632d36120cffffffff02a0860100000000001976a91483b62ff15ffd23e53fe8e551d11e9fad1ef1e7cf88acd0dd0600000000001976a9140222fa13d983610bcddcaf83e23f7ab7e092fc0288ac00000000000000000000000000000000000000 {"jsonrpc":"1.0","id":"curltest","result":null,"error":{"code":-1,"message":"the transaction will be rejected from the mempool until the next chain tip block: transaction did not pass consensus validation: could not convert an asynchronous verification error: downcast to known transaction error type failed, original error: ScriptInvalid"}}
router.post('/transfer', async (req, res) => {
const { utxos, destination, changeAddress, changeAmount } = req.body;
const toAddresses = JSON.stringify(destination);
try {
logger.info(
[transfer] ${toAddresses} ${changeAddress} ${changeAmount});if (!Array.isArray(destination) || !Array.isArray(utxos) || !changeAddress) {
throw new Error("Invalid destination or utxos format");
}
checkUtxos(utxos);
const outputUtxos = buildOutputs(destination, changeAddress, changeAmount);
const inputUtxos = buildInputs(utxos);
const net = networks.zcash;
//messagePrefix不影响签名和上链,只是为了匹配zel网络参数,可以不修改
if (name === "ZEL") {
net.messagePrefix = "\u0018ZelCash Signed Message:\n"
}
const builder = new ZcashTransactionBuilder(net);
builder.setVersion(Number(version));
builder.setVersionGroupId(parseInt(versionGroupId, 16));
builder.setConsensusBranchId(parseInt(consensusBranchId, 16));
for (const inputItem of inputUtxos) {
builder.addInput(inputItem.hash,
inputItem.index,
ZcashTransaction.DEFAULT_SEQUENCE,
address.toOutputScript(inputItem.address, net),
inputItem.value);
}
for (const outputItem of outputUtxos) {
builder.addOutput(outputItem.address, outputItem.value);
}
logger.info(
[transfer] ${toAddresses} ${changeAmount} unsignedTx: ${JSON.stringify(builder)});inputUtxos.forEach((input, index) => {
const keyPair = ECPair.fromWIF(input.wif);
if (keyPair) {
builder.sign({
vin: index,
keyPair: keyPair,
prevOutScriptType: 'p2pkh',
hashType: ZcashTransaction.SIGHASH_ALL
});
} else {
throw new Error(
keyPair not found for input at index ${index} ${input.address});}
});
// 完成所有输入的签名
const signedTransaction = builder.build();
const rawTx = signedTransaction.toHex();
logger.info(
[transfer] ${toAddresses} ${changeAmount} rawTx: ${rawTx});const response = await broadcast(rawTx);
if (response && response.result) {
logger.info(
[transfer] ${toAddresses} txHash: ${response.result});res.json({ code: 200, result: response.result, rawTx });
return;
}
throw new Error(response);
} catch (e) {
logger.error(
[transfer] failed ${toAddresses}, e);res.json({
code: -1, msg: (e.message || e)
});
}
});
const zcash = {
"name": "ZEC",
"port": "8000",
"dustValue": "5000",
"version": 4,
"versionGroupId": "0x892f2085",
"logDir": "zec",
//{"code":-26,"message":"16: old-consensus-branch-id (Expected 4dec4df0, found c8e71055)"}
// https://github.com/zcash/zcash/blob/master/src/consensus/upgrades.cpp#L58
//https://github.com/zcash/zcash/blob/master/src/consensus/upgrades.cpp#L63
"consensusBranchId": "0x5437f330",
"nodes": [
{
"url": "http://127.0.0.1:13341",
"username": "mxctest",
"password": "testqweasd"
}
]
};