1

I have a problem with raw Transaction. Using this code to send tokens to another contract, something does not work. The transaction is signed correctly, everything is sent to the network but it does not work.

   let gasCost = await tokenContract.transfer['address,uint256,bytes'].estimateGas(tradecenterAddress,web3.toWei(
                                            this.uint256,"ether"),
                                            web3.fromAscii(this.bytes),
                                            {from:this.creator});
        console.log(gasCost);

        let count = web3.eth.getTransactionCount(this.creator);



        var rawTransaction = {

            "from":this.creator,
            "nonce":"0x"+count.toString(16),
            "gasPrice":web3.eth.gasPrice.c[0],
            "gasLimit":gasCost,
            "to":SafeCoinAddress,
            "value":"0x0",
            "data:":tokenContract.transfer['address,uint256,bytes'].getData(tradecenterAddress,this.uint256,web3.fromAscii(this.bytes),{from:this.creator}),
            "chainId":1994
        };

        let tx = new window.ethereumjs.Tx(rawTransaction);
        let privateKey = window.keythereum.recover(this.password,fileOb);
        privateKey = privateKey.toString('hex');
        let buf = Buffer.Buffer.from(privateKey,'hex');
        console.log(privateKey);
        console.log(buf);
        tx.sign(buf);
        let serializedTx = tx.serialize();
        let recipt = await web3.eth.sendRawTransaction('0x'+serializedTx.toString('hex'));
        console.log(recipt);

Doing the same in this way everything works.

   let gasCost =  tokenContract.transfer['address,uint256,bytes'].estimateGas(tradecenterAddress,web3.toWei(44,"ether"),web3.fromAscii("fd"));
      console.log(gasCost);
       let hashT =   tokenContract.transfer['address,uint256,bytes'].sendTransaction(tradecenterAddress,web3.toWei(44,"ether"),web3.fromAsci

i("fd"),{from:account0,gas:gasCost});
  • What do you mean when you say it doesn't work? The transaction fails, it is marked pending and is never mined, or it is droped immediately? I'd suggest to check in your transaction if gasPrice and chainId are correct. – Ismael Aug 20 '18 at 23:50
  • Error say "Error: Returned error: known transaction: " and another time "Error: Transaction has been reverted by the EVM:" – Daniel Soe Aug 21 '18 at 22:43
  • If the transaction says it is reverted by the EVM it means the signature is ok, perhaps gas is too low. I don't know what the other error means perhaps you submitted the same transaction twice. – Ismael Aug 22 '18 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.