0

I have following small simple contract

pragma solidity 0.4.24;

contract MyContract {

    uint256 public  totalSupply ; 
    mapping( address => uint256) public  balances ;
    address public owner;

    constructor(address _wallet) public payable {
        totalSupply = 6;
        owner = _wallet;
    }

    function () external payable{
        buyToken();
    }

    function buyToken() public payable {
        require(totalSupply >= (msg.value/1000000000000000000)*2);
        balances[msg.sender] += (msg.value/1000000000000000000)*2;
        totalSupply -=(msg.value/1000000000000000000)*2;

    }
    function getTotalSupply()public view returns  (uint256 ){
        return totalSupply;
    }
       function setTotalSupply(uint256 newSupply) public {
        require(msg.sender==owner);
        totalSupply = newSupply;

    }

}

I want to deploy above contract using its abi, bin(extracted from json file generated by solc compiler version 0.4.24) and encoded constructor parameters. it gives following error;

 base fee exceeds gas limit

here is my code:

async function dep(0) {
var params;
const contract = new web3.eth.Contract(myAbi[0]);

      if(constructorParams[0]=='') {
          params = '0x' + myBin[0]
      } else {
          params = '0x' + myBin[0]+constructorParams[0]
      }


        try {
        await web3.eth.sendTransaction(
            {from:account1,
            data: params
                }, function(err, receipt) {console.log(receipt)});
        } catch (error) {
        console.log(" ERROR !", error); 
        }
}

Some values which may be required for your queries;

I am using Nodejs, Javascript, and Ganache GUI with gaslimit : 100000000, Gas price : 20000000000. Here is some values

constructorParams[0] :  0000000000000000000000000000000000000000000000000000000000000000
myAbi[0] : [
  {
    constant: true,
    inputs: [],
    name: 'totalSupply',
    outputs: [ [Object] ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
    signature: '0x18160ddd'
  },
  {
    constant: true,
    inputs: [ [Object] ],
    name: 'balances',
    outputs: [ [Object] ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
    signature: '0x27e235e3'
  },
  {
    constant: true,
    inputs: [],
    name: 'owner',
    outputs: [ [Object] ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
    signature: '0x8da5cb5b'
  },
  {
    constant: false,
    inputs: [],
    name: 'buyToken',
    outputs: [],
    payable: true,
    stateMutability: 'payable',
    type: 'function',
    signature: '0xa4821719'
  },
  {
    constant: true,
    inputs: [],
    name: 'getTotalSupply',
    outputs: [ [Object] ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
    signature: '0xc4e41b22'
  },
  {
    constant: false,
    inputs: [ [Object] ],
    name: 'setTotalSupply',
    outputs: [],
    payable: false,
    stateMutability: 'nonpayable',
    type: 'function',
    signature: '0xf7ea7a3d'
  },
  {
    inputs: [ [Object] ],
    payable: true,
    stateMutability: 'payable',
    type: 'constructor',
    constant: undefined
  },
  {
    payable: true,
    stateMutability: 'payable',
    type: 'fallback',
    constant: undefined
  }
]

myBin: 60806040526040516020806103cc83398101806040528101908080519060200190929190505050600660008190555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505061034d8061007f6000396000f300608060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806318160ddd1461008257806327e235e3146100ad5780638da5cb5b14610104578063a48217191461015b578063c4e41b2214610165578063f7ea7a3d14610190575b6100806101bd565b005b34801561008e57600080fd5b5061009761026e565b6040518082815260200191505060405180910390f35b3480156100b957600080fd5b506100ee600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610274565b6040518082815260200191505060405180910390f35b34801561011057600080fd5b5061011961028c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101636101bd565b005b34801561017157600080fd5b5061017a6102b2565b6040518082815260200191505060405180910390f35b34801561019c57600080fd5b506101bb600480360381019080803590602001909291905050506102bb565b005b6002670de0b6b3a7640000348115156101d257fe5b0402600054101515156101e457600080fd5b6002670de0b6b3a7640000348115156101f957fe5b0402600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055506002670de0b6b3a76400003481151561025c57fe5b04026000808282540392505081905550565b60005481565b60016020528060005260406000206000915090505481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054905090565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561031757600080fd5b80600081905550505600a165627a7a7230582013a524fedd05746ca684e0f9782f25f213e4ddceb23e1d60bd69d17a076fefea0029
  • Note that in your code, the if(constructorParams[0]=='') / else part is redundant. You can simply do const params = '0x' + myBin[0]+constructorParams[0];, or even get rid of this variable and do data: '0x' + myBin[0]+constructorParams[0];. – goodvibration Dec 12 '19 at 13:07
  • That said, check the size of your bin file. It cannot exceed 48K (representing a binary contract-size of 24k). Oh wait, I see it here at the bottom of your question, so forget it (just keep this restriction in mind for future reference). – goodvibration Dec 12 '19 at 13:12
  • thanks good suggestion... – Amir Ali Dec 13 '19 at 4:21
1

I am able to deploy your contract via the following:

async function send(web3, privateKey, params)
    const options = {
        data: params,
        gas: 2000000,
    };
    const signed = await web3.eth.accounts.signTransaction(options, privateKey);
    const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
    console.log(receipt.contractAddress);
}

It's deployed at 0xc40757e5E9FAaa9D3c7eEAd99d123F8042629B49 on Ropsten, in case you're interested.

| improve this answer | |
  • Thanks a lot , it works for me – Amir Ali Dec 13 '19 at 4:01

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.