6

I am currently trying my first contract on Ethereum but I never imagined that it would be so difficult...
I followed the guide here :

https://medium.com/ziggify/blockchain-stack-1-installing-ethereum-geth-and-your-first-smart-contract-7e9c4105e5eb

But I don't understand a things... :( Since I don't have solC, I use the solidity browser. When I copy the Web3 code into Geth

This one :

var _greeting = /"Hello World"/ ;
var hello world_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}]);
var hello world_greeter = hello world_greeterContract.new(
   _greeting,
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052341561000c57fe5b6040516103ac3803806103ac833981016040528080518201919050505b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b806001908051906020019061008292919061008a565b505b5061012f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100cb57805160ff19168380011785556100f9565b828001600101855582156100f9579182015b828111156100f85782518255916020019190600101906100dd565b5b509050610106919061010a565b5090565b61012c91905b80821115610128576000816000905550600101610110565b5090565b90565b61026e8061013e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610046578063cfae321714610058575bfe5b341561004e57fe5b6100566100f1565b005b341561006057fe5b610068610185565b60405180806020018281038252838181518152602001915080519060200190808383600083146100b7575b8051825260208311156100b757602082019150602081019050602083039250610093565b505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561018257600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b61018d61022e565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102235780601f106101f857610100808354040283529160200191610223565b820191906000526020600020905b81548152906001019060200180831161020657829003601f168201915b505050505090505b90565b6020604051908101604052806000815250905600a165627a7a723058208695872d7606c3275627d368d0f725b78862809aac0616b576a51d565efc1d1c0029', 
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

And This one :

var hello world_mortalContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);
var hello world_mortal = hello world_mortalContract.new(
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052341561000c57fe5b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b5b6101088061005f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514603a575bfe5b3415604157fe5b60476049565b005b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141560d957600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820d438d032342c88b4259801b5769aed2e2e221aa8058b7efd4f39112ee8b73b3f0029', 
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

I got these 2 errors messages :

>
>
undefined
>
(anonymous): Line 1:11 Unexpected identifier (and 1 more errors)
>
...
...
......
......
......
......
......
......
.........
.........
......  })
(anonymous): Line 1:11 Unexpected identifier (and 7 more errors)
>
...
......
......
......
......
......
......
.........
.........
......  })
(anonymous): Line 1:11 Unexpected identifier (and 4 more errors)

I am completely lost, I already spend half a day reading guide and other tutorial about the same contract but no one explain how to solve this problem :( Everytime, it seems like someone use a slightly different method... it makes me crazy !

Plus, does someone know the right way to learn about smart-contract and how to use it ? I have a private blockchain with 1 static node, and 3 nodes.

Thank you very much :)

1

Welcome to Ethereum - a world of dragons and tools that constantly outpace any documentation.

I would suggest that you start playing with smart contracts (e.g. the greeter) only in the browser using Remix. You can copy-paste the greeter example into the browser editor and play with your smart contract there. Everything will only run in your browser but already behave in the same way as a "real" blockchain

If you are ready to go on a "real" public blockchain you need Ether to send any transactions (you pay for something called "gas" as a transaction fee). Once you bought some Ethere or got some from a friend and really want to go on the public main chain and interact with it via geth you have to first create an account in the geth JS console via web3.personal.newAccount. Next you can check if that worked via web3.eth.accounts and copy paste the address into a blockchain explorer such as etherscan.io and see your balance. You can also transfer yourself some Ether to get going. Only then can you use the deploy code (to bring that contract onto the main Ethereum chain) as outlined in the example that you found.

  • Hi ! Thank you for your answer ! :) I have already successfully deployed a private blockchain with 4 nodes, sent ether between them, checked their balance, unlock the account ^^ That's why I am trying to deploy the most basic contract but It seems like that it is more difficult than it looks... :( – Ashord May 17 '17 at 10:02

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.