Msg.sender in contract is empty


I have the following deployment script

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

                console.log("Deploying the contract");


Everything seems to work also my contracts is deployed

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 returns 0x0000000000000000000000000000000000000000

1 Like

Hello @martin1, welcome to the forum!

It looks like your contract was deployed with no code (see here), which is why no function call will work.

Which version of web3 are you using? The gas was indeed set correctly, maybe you’re creating the contract wrong? What is in response.abi?


web3 is injected with MetaMask
{api: “0.20.3”, getNode: ƒ, getNetwork: ƒ, …

and bytecode


Also my 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 {


Your contract is fine, though your web3 version is old (and I couldn’t find documentation for it), you may want to switch to v1.0.beta-37, though bear in mind there are some breaking changes involved.

That said, I believe your issue is that you’re creating the contract object from the ABI, which doesn’t have the bytecode: that will allow you to interact with existing contracts (since it knows their interface), but not to create new ones (since it doesn’t know how the interface is implemented). Sadly I don’t know what the proper what to create a web3 0.20 contract from bytecode is. It looks like on 1.0 new doesn’t exist anymore, but there’s a deploy function that receives the bytecode in data, maybe that’s what you’re supposed to do?


Same result

var contract = new web3.eth.Contract(response.abi);
var bytecode = response.bytecode;

            console.log("Deploying the contract");
                    from: web3.currentProvider.selectedAddress,
                    gas: 1004000,
                .on('error', function (error) {
                .on('transactionHash', function(transactionHash) {
                    console.log("Hash: " + transactionHash)
                .on('receipt', function(receipt) {
                    console.log("Contract address" + receipt.contractAddress) // contains the new contract address

Web3 version is latest
The solc compiled the code is pragma solidity ^0.5.2;


That transaction failed because it run out of gas (note that 100% of your 1,004,000 gas was spent): increase the gas limit before sending it.


Thank you very much - it is working now :slight_smile:
Before I change the version of web3js this was the maximum I was allowed to set.
So because of this I dont rise the limit.