1

TL:DR My first contract fails to deploy reporting variously:

  • Error: intrinsic gas too low undefined
  • Error: The contract code couldn't be stored, please check your gas amount. undefined

Having just investigated Hyperledger Fabric, I thought I'd try my hand at converting it's fabcar example to Ethereum.

I'm running an Ethereum private network with:

geth --dev --ipcpath ${HOME}/Library/Ethereum/geth.ipc

and then attaching to this with:

geth attach ipc://${HOME}/Library/Ethereum/geth.ipc

I wrote fabcarSource.sol using an example (link) and taking some feedback from solc. The original uses an associative array (JavaScript object here) but the sample I followed uses a regular array and so I am here at least to get this deployed. [Feedback welcome.]

pragma solidity ^0.4.9;

contract Fabcar {

    struct Car {
        string colour;
        string make;
        string model;
        string owner;
    }

    Car[] cars;

    function changeCarOwner (uint k, string newOwner)
        public
    {
        if (k<cars.length) {
            cars[k].owner = newOwner;
            return true;
        } else {
            return false;
        }
    }
    function createCar(string colour, string make, string model, string owner)
        public
        returns (uint)
    {
        return cars.push(Car(colour,make,model,owner));
    }
    function initLedger() {
        cars.push(Car("Dark Gray","Ford","Escape","Daz"));
        cars.push(Car("Blue","Audi","A5","Karo"));
    }
    function queryCar(uint k)
        public
        view
        returns (Car)
    {
        if (k<cars.length) {
            return cars[k];
        }
    }
    function queryAllCars()
        public
        view
        returns (Car[])
    {
        return cars;
    }


}

Per my guide (link):

echo var fabcarSource = > fabcarSource.js && \
solc --combined-json abi,bin,interface fabcarSource.sol >> fabcarSource.js

and then:

personal.unlockAccount(eth.accounts[0]);
loadScript("fabcarSource.js");
var fabcarContract = web3.eth.contract(
  JSON.parse(fabcarSource.contracts["fabcarSource.sol:Fabcar"].abi));
var gasValue = eth.estimateGas({
  date:"0x"+fabcarSource.contracts["fabcarSource.sol:Fabcar"].bin
});

and a check:

> gasValue
53000

and, after more Googling:

> eth.getBlock("latest").gasLimit
4712388
> eth.getBalance(eth.coinbase)
4.875e+21

BUT:

var fabcar=fabcarContract.new(
  {
    from:eth.accounts[0],
    data:"0x"+fabcarSource.contracts["fabcarSource.sol:Fabcar"].bin,
    gas:400000
  },
  function(e,contract){
    console.log(e,contract);
    if (typeof contract.address !== "undefined") {
      console.log(
        "Contract mined! Address: " + contract.address + 
        " transactionHash: " + contract.transactionHash
      );
    }
  }
);

and using gasValue, gasValue+50000, 300000 (tutorial), 500000 results in the errors up-top.

Any help would be much appreciated!

As others have pointed out, the getting started instructions are frustratingly out-of-date and increase abandonment. Please fix!

https://ethereum.org/greeter

I found several very helpful links: one on StackExchange for using a private network (link) and another that got me a sample deployed (link) and I was able to get greeter deployed thanks to them. But this took time and I remain close to giving up.

  • Aha! Perhaps partly a consequence of (a) indeterminate string sizes with the Car struct (and functions)? I found this question regarding Solidity examples using bytes32 instead of string; (b) missing 'payable' for mutators. I will see whether these make a difference to the Deployment. (ethereum.stackexchange.com/questions/3795/…) – DazWilkin Oct 31 '17 at 23:28
  • These did not make a difference :-( – DazWilkin Oct 31 '17 at 23:44
  • I was able to use ethereum.github.io/browser-solidity to create a web3deploy that I was (!) able to deploy. It has gas: '4700000' (string) but... I then encounter problems with an inability to return Structs from functions etc. – DazWilkin Nov 1 '17 at 0:44
  • I am able to deploy using my example above by setting gas to 4.7m as with the web3deploy but as an int value not a string. So, that's one problem solved. – DazWilkin Nov 1 '17 at 0:48
0

I believe my deployment errors were solely related to an incorrect gas value.

It remains unclear to me how to determine the gas value for deployments when eth.estimateGas was so far from the value I needed.

Setting the gas value to 4.7m (in this case) works, reliably.

The value is approximately eth.getBlock("latest").gasLimit (4,712,388) and I assume that's relevant.

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.