您现在的位置:kastop>> Kas信息 Kaspa网络>>正文内容

转账0.2kas手续费却有9.8KAS的问题

问题:

I tried to transfer 0.2 KAS to another wallet.

It went through successfully but it says the Tx Fee is 9.8 KAS. It is not normal that high.

Here is the tx:

https://explorer.kaspa.org/txs/4474c21f925dccbd9101d1d07c97158ef66ea7007566dc81e118026296f5ab48

Kaspa explorer

This is a Kaspa explorer for a DAG overview. You can query addresses, blocks and transactions.

Here is my code that used to send kas

try {

const { entries : utxos } = await rpc.getUtxosByAddresses([address]);

console.info(utxos);

if (utxos.length === 0) {

console.info('Send some kaspa to', address, 'before proceeding with the demo');

return;

}

let total = utxos.reduce((agg, curr) => {

return curr.amount + agg;

}, 0n);

const outputs = [{

address:address2ndWallet,

amount: 20000000n

//    address,

//    amount: total - BigInt(utxos.length) * 2000n,

}];

const changeAddress = address;

console.log("changeAddress:", changeAddress)

const tx = createTransaction(utxos, outputs, changeAddress, 0n, 0, 1, 1);

console.info("Transaction before signing:", tx);

const transaction = signTransaction(tx, [privateKey], true);

console.log("Transaction:", transaction);

let result = await rpc.submitTransaction({transaction});

console.info("submitTransaction result:", result);

} finally {

await rpc.disconnect();

}


解答:

您1)没有正确使用API。您应该使用事务生成器类来创建事务

2)(将由事务生成器解决)-您没有创建更改输出,因此所有剩余资金都将用于费用,因为费用是输出的总和-输入的总和。

请使用事务生成器示例作为参考。

我认为这是压垮骆驼的最后一根稻草。我想删除createTransaction(),但其他开发者希望它存在,所以我将其重命名为createUnsafeTransaction()或createRawTransaction(。

但在您现在的情况下,您需要创建一个更改输出,以便更改返回到您的更改地址。

示例:

rusty-kaspa/wasm/examples/nodejs/javascript/transactions/utxo-context-generator.js at typescript · aspectron/rusty-kaspa · GitHub



感动 同情 无聊 愤怒 搞笑 难过 高兴 路过
【字体: 】【收藏】【打印文章】 【 打赏 】 【查看评论

相关文章

    没有相关内容