ethereumjs / ethereumjs-tx

Project is in active development and has been moved to the EthereumJS VM monorepo.
https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/tx
Mozilla Public License 2.0
779 stars 235 forks source link

TxReciept Status Failed while deploying a contract #91

Closed sathyamlokare closed 5 years ago

sathyamlokare commented 6 years ago

Why is contract creation failing here, I have tried with almost all the version of web3, its still failing.

Can anyone try to solve this

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/"));

var Tx = require('ethereumjs-tx');
const testHashCoinAdvanced = require('./build/TokenERC20.json');

var privateKey = new Buffer('f6da78c45601d9ae02fcdb161e44a15a99e5e1fb1aa931dd95366add5dec367e', 'hex')

const deploy = async()=>{
  testCoinRinkeby = new web3.eth.Contract(JSON.parse(testHashCoinAdvanced[':TokenERC20'].interface), null, {
              data: testHashCoinAdvanced[':TokenERC20'].bytecode,
          });

  testCoinContractDeploy = await testCoinRinkeby.deploy({
              arguments: [ 1000,"HashCoin","HC" ]
          });
           var contract = new web3.eth.Contract(JSON.parse(testHashCoinAdvanced[':TokenERC20'].interface));
          const hexdata = contract.deploy({
              data: '0x' + testHashCoinAdvanced[':TokenERC20'].bytecode,
              arguments:[1000,"HashCoin","HC"]
           }).encodeABI()

           const nonce = await web3.eth.getTransactionCount( "0x7Fb11F6A52e20BDFfaa08c468cD4848b901b7B70" );
           const nonceHex = web3.utils.toHex(nonce)
const gasPriceHex = web3.utils.toHex(3 * 1e9);
// const estimatedGas = await testCoinContractDeploy.estimateGas();
  var rawTx = {
      nonce: nonceHex,
      gasPrice: web3.utils.toHex(30000000000),
      gasLimit: web3.utils.toHex(6100500),
      data: "0x"+hexdata
  }

  var tx = new Tx(rawTx);
  tx.sign(privateKey);

  var serializedTx = tx.serialize();

  console.log(serializedTx.toString('hex')); // f86180825208825208948005ceb675d2ff8c989cc95354438b9fab56868101801ca096e0cb2e633f07a7ee1f761dba1109c18a44550692305c03c72403ffa0b8fc12a012482fd916fa0a05396fadbf13b39619193e9f80dd5a0fd32086257cc3a11796

  web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
      .on('receipt', console.log);

};
deploy();

Here is the transaction history https://rinkeby.etherscan.io/address/0x7fb11f6a52e20bdffaa08c468cd4848b901b7b70

holgerd77 commented 5 years ago

Will close, since this is too long ago and not sure if cause is really by the tx library. Sorry that there was no one for assistance at time.