尝试发送已签名的交易时发件人错误

时间:2019-03-02 20:45:55

标签: javascript node.js ethereum solidity web3

im试图在节点js中发送RAW事务。我将一些参数传递给交易,然后用我的私钥对其进行签名。当我这样做时,然后将txHash发送到Rinkeby网络。然而,即时消息却显示“天然气的不足资金*价格+价值”。

看起来很奇怪的是,当我解码交易时,发件人地址与我在交易参数中传递的“发件人”字段完全不同 任何想法为何与众不同?

当我使用im签名修改私钥时,还有另一个不同的发件人地址-私钥中是否存在某些问题?我似乎可以通过例如MEW

使用私钥登录我的帐户。

我的代码:

    const web3 = new Web3(new Web3.providers.HttpProvider(config.ethNodeURL));
var multiSig = new web3.eth.Contract(abi, multiSigAddress); //'0x2ea7b894702873daf8036ad870b671bb2caa9a36');
let txBuilder = multiSig.methods.submitTransaction(toAddress, value, []);
let encodedTx = txBuilder.encodeABI();

const gasPrice = await web3.eth.getGasPrice();
const nonce = await web3.eth.getTransactionCount(fromAddress);
const gasPriceLimit = await web3.eth.estimateGas({
     "from"      : fromAddress,       
     "nonce"     : nonce, 
     "to"        : toAddress,     
     "data"      : encodedTx
    });

const txParams = {
    nonce: nonce,
    gasPrice: gasPrice,
    gasLimit: 60000,
    to: toAddress,
    from: fromAddress,
    data: encodedTx,
    // EIP 155 chainId - mainnet: 1, ropsten: 3
    chainId: config.ethChainId
}

web3.eth.accounts.signTransaction(txParams, privateKey, function (error, signedTx) {
    if (error) {
        console.log(error);
    } else {
        console.log(signedTx);

        console.log(signedTx.rawTransaction);
        console.log(new EthereumTx(signedTx.rawTransaction).getSenderAddress().toString('hex'));
        //THAT above console log logs some completely random address instead of the one passed in "from" in txParams
    }
});

0 个答案:

没有答案