contractAddress: null

by qi li   Last Updated August 14, 2019 04:28 AM

I use sendSignedTransaction to send the contract and return contractAddress: null

  let rpcUrl = "https://ropsten.infura.io/v3/6756e6f8f0e34482a262a7cf1d15f2c2";

var web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl)); var input = { language: 'Solidity', sources: { 'HelloWorld.sol': { content: 'pragma solidity ^0.5.10; contract HelloWorld { function f() public { } }' } }, settings: { outputSelection: { '': { '': ['*'] } } } }

var compiled = solc.compile(JSON.stringify(input)) var output = JSON.parse(compiled); var bytecode = output.contracts["HelloWorld.sol"]['HelloWorld'].evm.bytecode.object const privateKey = Buffer.from( 'my privatekey', 'hex' )

web3.eth.getTransactionCount("0x146DD8c053d94354C75783Ff8846012C8907Df17").then(function (transactionCount) { console.log(web3.utils.toHex(transactionCount)); var txParams = { nonce: web3.utils.toHex(transactionCount), gasPrice: web3.utils.toHex(1000), gasLimit: web3.utils.toHex(1000000), to: '0x0000000000000000000000000000000000000000', value: '0x00', data: "0x" + bytecode, } const tx = new Tx(txParams, { 'chain': 'ropsten' }) tx.sign(privateKey) const serializedTx = tx.serialize()

var receipt=null;

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), function (err, hash) {
  console.log(err);
  console.log(hash);
  while (receipt == null) {

    receipt = web3.eth.getTransactionReceipt(hash);

  }

  console.log('Contract address: ' + receipt.contractAddress);

});

Tags : web3js


Answers 1


{ blockHash:

'0x6a77b44ca49bd3a822d7a033251cc425941c6a184b555c3242831f4180ff7ebf', blockNumber: 6183868, contractAddress: null, cumulativeGasUsed: 5492997, from: '0x146dd8c053d94354c75783ff8846012c8907df17', gasUsed: 29740, logs: [], logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', status: true, to: '0x0000000000000000000000000000000000000000', transactionHash: '0x44adb75d7ee2d0fa0ba939784354f9b0fe512887d988711296995973c20be4a1', transactionIndex: 12 }

qi li
qi li
August 14, 2019 03:33 AM

Related Questions


Updated January 06, 2019 18:28 PM

Updated December 20, 2018 15:28 PM

Updated August 09, 2019 05:28 AM

Updated August 12, 2019 09:28 AM

Updated November 19, 2018 05:28 AM