0

I'm trying to deploy a very simple smart contract on Ropsten through Infura When I launch (on Ubuntu) my deploy.js script, everything seems to work except I don't get the contractAddress in the receipt The deployment of the same smart contract works fine on Remix, and I'm using the same account I'm getting the bin assembly from Remix or solcjs on the same machine

Pretty frustrating...

nicola@geth2:~/ethnow$ node deploy.js 
(node:4348) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
0x5d
0x280ae02eb54e65fbfc2f0da87e67ad7203abee77daa00d73982dc7b67217cd03
undefined
{ blockHash:
   '0x3e9c216ab012194c35761545201568bd4cac851a308222a7dd47b889a85db9c0',
  blockNumber: 7454336,
  contractAddress: null,
  cumulativeGasUsed: 25796,
  from: '0x4f73dc0aafbfab1151b5823a66736a8f46fa49e6',
  gasUsed: 25796,
  logs: [],
  logsBloom:
   '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  status: true,
  to: '0x0000000000000000000000000000000000000000',
  transactionHash:
   '0x280ae02eb54e65fbfc2f0da87e67ad7203abee77daa00d73982dc7b67217cd03',
  transactionIndex: 0 }

Smart comntract:

pragma solidity ^0.6.0;

contract SimpleStorage {
    uint storedData;

    event Set(
        address indexed _from,
        uint _storedData
    );

    function set(uint x) public {
        storedData = x;
        emit Set(msg.sender, storedData);
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

Deploy script

var Web3 = require('web3');
var Tx = require('ethereumjs-tx');
//const fs = require('fs');
//const solc = require('solc');

//WSS INFURA wss
//var web3 = new Web3(new Web3.providers.WebsocketProvider('wss://:324af3552e8f4cb389c324e18131659b@ropsten.infura.io/ws/v3/1ef4898b08a84c3b98c755cd48476b92'));

//HTTPS
var web3 = new Web3(new Web3.providers.HttpProvider('https://:324af3552e8f4cb389c324e18131659b@ropsten.infura.io/v3/1ef4898b08a84c3b98c755cd48476b92'));

var privateKey = new Buffer('-----------------', 'hex');

//var abi = [{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","nam$

web3.eth.getTransactionCount("0x4f73Dc0AAFbFAb1151B5823a66736A8F46Fa49E6").then(function(res){


_nonce = web3.utils.toHex(res);

console.log(_nonce);


var rawTx = {
  from: "0x4f73Dc0AAFbFAb1151B5823a66736A8F46Fa49E6",
  nonce: web3.utils.toHex(_nonce),
  gasLimit: web3.utils.toHex(3000000),
  gasPrice: web3.utils.toHex(20000000000),
  to: '0x0000000000000000000000000000000000000000',
  value: '0x00',
  data: '0x608060405234801561001057600080fd5b50610117806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146062575b600080fd5b606$
  chainId: web3.utils.toHex(3)
}

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

var serializedTx = tx.serialize();

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('transactionHash', console.log)
.on('receipt', function(err, res){console.log(res); console.log(err)})
.on('error', console.log);


}
)
  • Thank you for publishing project ID 1ef4898b08a84c3b98c755cd48476b92. – goodvibration Mar 4 at 18:26
  • There's nothing in it... – Nicola Mar 4 at 18:31
  • I think a got the answer anyway, you need to use null as the target address for the transaction, not 0x0 – Nicola Mar 4 at 18:34
  • Other people will use it, and you'll get rate-limit apply on your account even though it wasn't you who used it. – goodvibration Mar 4 at 20:02
  • And you can simply omit the to field from the rawTx object. – goodvibration Mar 4 at 20:03
0

I think you need to remove to in rawTx.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.