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!
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.
gas: '4700000'
(string) but... I then encounter problems with an inability to return Structs from functions etc. – DazWilkin Nov 1 '17 at 0:44