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 {

}
  • can you try data: '0x' + bytecode? I had a similar issue a while back. this fixed that. – Iftifar Taz May 10 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..... – Martin Tonev May 10 at 15:06
  • there need to be 1 0x – Iftifar Taz May 10 at 16:31
  • Yes, I know and that is why I dont add it – Martin Tonev May 10 at 20:22
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
};
  • 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 – Martin Tonev May 5 at 20:24
  • Are you have any idea why is this happening? – Martin Tonev May 6 at 8:46
  • Not without seeing your updated code. Ideally your smart contact code as well. – user19510 May 6 at 15:09
  • I just added it, thanks – Martin Tonev May 7 at 7:20
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, privacy policy and cookie policy

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