0

I have the following deployment script

var contract = web3.eth.contract(response.abi);
                var bytecode = response.bytecode;
                var options = {
                    from: web3.eth.defaultAccount,
                    gas: 1004000,
                    data: bytecode
                };

                console.log("Deploying the contract");

                contract.new(options

Everything seems to work also my contracts is deployed

https://ropsten.etherscan.io/address/0x12c135a0f44940f34379a063118a2a08143c3262

The problem is msg.sender is empty into the contracts and the function return 0x0000000000000000000000000000000000000000

this is set in the constructor in the Ownable OpenZeppelin contract but deployed this way it return 0x0000000000000000000000000000000000000000

My ABI https://pastebin.com/0XU4heNN

and bytecode https://pastebin.com/ThnDd1FC

The contract

pragma solidity ^0.5.2;

import '../../../node_modules/openzeppelin-solidity/contracts/ownership/Ownable.sol';
import '../../../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol';

contract PropertyContract is ERC20Mintable, Ownable {

}
4
  • can you try data: '0x' + bytecode? I had a similar issue a while back. this fixed that. Commented May 10, 2019 at 12:13
  • I think this can help in older version - now 0x is in the bytecode pastebin.com/ThnDd1FC Let me know if there must be two 0x0x..... Commented May 10, 2019 at 15:06
  • there need to be 1 0x Commented May 10, 2019 at 16:31
  • Yes, I know and that is why I dont add it Commented May 10, 2019 at 20:22

2 Answers 2

2

You didn't actually send any bytecode, so a contract got created with no code. No calls to it will do anything useful.

var options = {
  from: web3.eth.defaultAccount,
  gas: 1004000,
  data: "<bytecode here>", // <-- add this
};
3
  • When I add it my bytecode the contract fails to deploy because "out of gas", I try to increase it but when I increase I reach the maximum Commented May 5, 2019 at 20:24
  • Are you have any idea why is this happening? Commented May 6, 2019 at 8:46
  • Not without seeing your updated code. Ideally your smart contact code as well.
    – user19510
    Commented May 6, 2019 at 15:09
0

Everything was fixed when I move to latest web3.js 1.0 and instead of

contract.new()

I use now the deploy method from the version and everything seems to work fine

contract.deploy({
                        data:bytecode
                    })
                    .send({
                        from: web3.currentProvider.selectedAddress,
                        gas: 6004000,
                    })
                    .on('error', function (error) {
                        console.log("Error: " +error)
                    })
                    .on('transactionHash', function(transactionHash) {
                        console.log("Hash: " + transactionHash)
                    })
                    .on('receipt', function(receipt) {
                        console.log("Contract address: " + receipt.contractAddress) // contains the new contract address
                    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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