5

I have followed this guide https://ethereum.stackexchange.com/a/2787/2426 (or equivalently https://www.ethereum.org/greeter ) when trying to deploy a simple Smart Contract into Ethereum testnet. I am using geth CLI on testnet. Everything works except final step, uploading code at blockchain. This is what I did:

GETH SECOND INSTANCE:

geth --testnet --unlock 0 attach ipc:.ethereum/testnet/geth.ipc
    instance: Geth/v1.4.10-stable-5f55d95a/linux/go1.6.2
    coinbase: 0x47978a69f410d0f61850c92acdb0d4c464d70937
    at block: 1697809 (Mon, 26 Sep 2016 07:10:20 UTC)
     datadir: .ethereum/testnet
     modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> web3.fromWei(eth.getBalance(eth.accounts[0]).toNumber(), "ether")
"5.024681313417504"

COMPILE:

> var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) suicide(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'

> var greeterCompiled = web3.eth.compile.solidity(greeterSource)

INSERT THE CONTRACT CODE INTO THE BLOCKCHAIN:

> var _greeting = "Good Morning, Smart Contract!"

> var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

> var greeter = greeterContract.new(_greeting, {from: eth.accounts[0], data: greeterCompiled.greeter.code, gas: 4000000}, function(e, contract) { if (!e) { if (!contract.address) { console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); } else { console.log("Contract mined! Address: " + contract.address); console.log(contract); } } })

> debug.verbosity(4)

When exploring greeter, this is the output:

> greeter
    {
      abi: [{
          constant: false,
          inputs: [],
          name: "kill",
          outputs: [],
          payable: false,
          type: "function"
      }, {
          constant: true,
          inputs: [],
          name: "greet",
          outputs: [{...}],
          payable: false,
          type: "function"
      }, {
          inputs: [{...}],
          type: "constructor"
      }],
      address: undefined,
      transactionHash: null
    }

> greeter.greet();
    TypeError: 'greet' is not a function
        at <anonymous>:1:1

I wait a minute and got no message like this:

Contract mined! address: 0x...

So, contract seems to be properly compiled but I cannot obtain nor address, nor txHash after uploading into blockchain. Maybe it's not been uploaded, or mined. How can I figure it out? Did I miss something important?

Edit: Right after trying to deploy log is reporting a lot of messages like this one:

I0926 10:31:13.097817 core/state/state_object.go:160] 47978a69f410d0f61850c92acdb0d4c464d70937: #1048576 631783523629846744286 (+ 420000000000000)

Being 0x47978a69f410d0f61850c92acdb0d4c464d70937 the coinbase address of the geth node.

  • 1
    do you have enough test ether to deploy a contract? – 4gn3s Sep 26 '16 at 11:06
  • I guess so, 5 ethers. Is that enough? – Juan Ignacio Pérez Sacristán Sep 26 '16 at 12:03
4

The problem is that your command geth --testnet --unlock 0 attach ipc:.ethereum/testnet/geth.ipc does not actually unlock the account. This command just attaches the console to the running geth instance.

If you had used geth --testnet --unlock 0 console instead, you will be asked to unlock your account with the following message:

Unlocking account 0 | Attempt 1/3
Passphrase: 
I0926 21:48:25.702979 cmd/geth/accountcmd.go:189] Unlocked account 3b44...a400

If you want to use the geth ... attach command, run the following command just before you execute your transactions:

personal.unlockAccount(eth.accounts[0], "{your password}");

This will unlock your account and then enable the payment for the transaction.

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.