0

I am getting an error today, when tried to mine a contract to ethereum testnet. Even after the transaction is mined successfully (I can check that in the Testnet), the call back is executing the code inside the error.

The callback function in my java script as follows:

function mine_pContract(byteCode, abi, estimatedGas) {
console.log(abi);
var MyContract = web3.eth.contract(JSON.parse(abi));

var myContractReturned = MyContract.new({
    from: web3.eth.accounts[0],
    data: byteCode,
    gas:estimatedGas}, function(err, myContract) {
    if (err) {
        console.log("Error while mining the contract" + err)
    }
    else {
        if (!myContract) {
            console.log("Contract transaction sent. Transaction Hash" + myContract.transactionHash + "waiting to be mined");
        }
        else {
            if (myContract.address === undefined) {
                console.log("still mining. Transaction Hash= " + myContract.transactionHash)
            }
            else {
                console.log("Contract mined. Address" + myContract.address);
            }
        }
    }
  });
} 

The output is: still mining. Transaction Hash= 0x859cbff73bf7da136f1b5402f1d9a7948608d6ef82c9e5f956db3e576fa5d720 main.js:262

Error while mining the contractError: The contract code couldn't be stored, please check your gas amount.

But it was supposed to showthe following message Contract mined. Address: 0xxxxxxxx.

Any one can point out where is the problem?

  • The obvious problem would be that you're not sending enough gas. How are you setting the estimatedGas variable? – Edmund Edgar Apr 27 '17 at 0:52
  • I am just passing a value from my HTML.... I tried with pretty high amounts (600000 - 1000000). It doesn't seems to be a problem with gas amount. The transaction are mined successfully if I track through the ropsten ui (ropsten.etherscan.io/tx/…). But, in the callback it is returning error before mining. The same code in fact work for me before (1 week). It's not working from today. Is it because of some network delay or something else? – Arghya Kusum Das Apr 27 '17 at 6:55
  • Can you share the constructor function of your contract? – Aniket Apr 27 '17 at 7:12
  • t's the most basic contract. The code is as follows: pragma solidity ^0.4.0; contract Patient { string public swarmHashP = "76565ef4c1609f619e57f97956454b0b78c1e0b1067677f26839b3dc565‌​67a56465"; function changeLocation(string _newSwarmHashP) { swarmHashP = _newSwarmHashP; } } – Arghya Kusum Das Apr 29 '17 at 20:26
0
                contract = this.web3.eth.contract(abi);
                contract.new(Params.toString(), {
                    from: this.web3.eth.defaultAccount,
                    data: code,
                    gas: estimatedGas
                }, (error, contractInst) => {
                    if(error) {
                        console.log(error);
                    } else if(contractInst.address){
                        console.log(contractInst);
                    }
                });

This is how I am using mined contract in my Dapp. Try to make correction followed by my example and hope it will work.

For more info check https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract

|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.