Implementación de contrato inteligente en la red de prueba de Ethereum

Seguí esta guía https://ethereum.stackexchange.com/a/2787/2426 (o de manera equivalente https://www.ethereum.org/greeter ) al intentar implementar un contrato inteligente simple en la red de prueba de Ethereum. Estoy usando geth CLI en testnet. Todo funciona excepto el paso final, cargar el código en blockchain. Esto es lo que hice:

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"

COMPILAR:

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

INSERTAR EL CÓDIGO DEL CONTRATO EN LA CADENA DE BLOQUES:

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

Al explorar el saludo, este es el resultado:

> 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

Esperé un minuto y no recibí ningún mensaje como este:

Contract mined! address: 0x...

Por lo tanto, el contrato parece estar correctamente compilado, pero no puedo obtener ni la dirección ni el txHash después de cargarlo en la cadena de bloques. Tal vez no ha sido subido o extraído. ¿Cómo puedo averiguarlo? ¿Me perdí de algo importante?

Editar: justo después de intentar implementar el registro, se informan muchos mensajes como este:

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

Siendo 0x47978a69f410d0f61850c92acdb0d4c464d70937 la dirección coinbase del nodo geth.

¿Tiene suficiente éter de prueba para implementar un contrato?
Supongo que sí, 5 éteres. ¿Es suficiente?

Respuestas (1)

El problema es que su comando geth --testnet --unlock 0 attach ipc:.ethereum/testnet/geth.ipcen realidad no desbloquea la cuenta. Este comando simplemente conecta la consola a la gethinstancia en ejecución.

Si hubiera utilizado geth --testnet --unlock 0 consoleen su lugar, se le pedirá que desbloquee su cuenta con el siguiente mensaje:

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

Si desea utilizar el geth ... attachcomando, ejecute el siguiente comando justo antes de ejecutar sus transacciones:

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

Esto desbloqueará su cuenta y luego habilitará el pago de la transacción.

Muchas gracias. ¡Ahora funciona!