Estoy trabajando en el tutorial de contratos. Aquí está el código (incluido el contrato):
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)
var _greeting = "Hello World!"
var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);
var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 10000000000000}, 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);
}
}
})
En la línea superior, el código fuente del contrato se escribe sin saltos de línea.
Tengo 4 ether para testnet:
> eth.getBalance(eth.coinbase)
4000000000000000000
Le invitamos a enviarme algunos más:
> eth.accounts
["0x425434d3a0f5da79d60769f2400896f0d85b41ec"]
En la geth-1.4.6
consola, importo el script completo desde arriba usando
> loadScript("/home/work/projects/contracts/tutorial_greeter/setup_greeter.js")
true
La compilación funciona, pero ¿por qué no tiene una dirección incluso cuando se han extraído varios bloques mientras tanto?
> greeter
{
abi: [{
constant: false,
inputs: [],
name: "kill",
outputs: [],
type: "function"
}, {
constant: true,
inputs: [],
name: "greet",
outputs: [{...}],
type: "function"
}, {
inputs: [{...}],
type: "constructor"
}],
address: undefined,
transactionHash: null
Aquí hay una guía paso a paso para implementar y ejecutar Greeter en Testnet.
Si aún no tiene una cuenta de coinbase, ejecute el siguiente comando:
user@Kumquat:~$ geth --testnet account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat Passphrase:
Address: {730b87e78b07fb2bf1b1e8b127b3353d08d72706}
Luego comience geth --testnet
en Testnet con el --mine --minerthreads 1 --unlock 0
parámetro con el console
comando. Deberá ingresar su contraseña para desbloquear la cuenta:
user@Kumquat:~$ geth --testnet --mine --minerthreads 1 --unlock 0 console
...
Unlocking account 0 | Attempt 1/3
Passphrase:
> I0615 01:37:11.434270 ethash.go:291] Generating DAG: 0%
I0615 01:37:19.280918 ethash.go:291] Generating DAG: 1%
...
I0615 01:40:09.629009 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 120 txs in 2.822940573s. #1039346 [534c4f03 / c9f46493]
I0615 01:40:09.723141 ethash.go:291] Generating DAG: 17%
...
I0615 01:59:43.271478 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 366 txs in 6.860619737s. #1113842 [cb034c71 / 909241a8]
I0615 01:59:48.964948 ethash.go:291] Generating DAG: 100%
I0615 01:59:48.969898 ethash.go:276] Done generating DAG for epoch 34, it took 22m39.495183713s
I0615 01:59:50.226735 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 401 txs in 6.953559841s. #1114098 [2f30678a / aa5b5fd1]
El DAG ahora se ha creado y la cadena de bloques aún se está descargando, del imported 256 block(s)
mensaje anterior.
Tenga en cuenta que no tiene que extraer la cadena de bloques de Testnet, ya que otro minero (si lo hay) recogerá su transacción e incluirá su transacción en un bloque extraído.
Puede verificar el estado de sincronización usando el siguiente comando:
> eth.syncing
{
currentBlock: 1123788,
highestBlock: 1133372,
knownStates: 0,
pulledStates: 0,
startingBlock: 1024655
}
> I0615 02:02:03.312407 core/blockchain.go:959] imported 256 block(s) (0 queued 0 ignored) including 306 txs in 8.307949518s. #1123826 [e9d853f5 / a549429b]
La cadena de bloques ahora ha terminado de sincronizarse. Verifiquemos el estado de la minería y nuestra cuenta de coinbase:
I0615 02:09:36.554320 miner/worker.go:555] commit new work on block 1133511 with 0 txs & 0 uncles. Took 293.439µs
I0615 02:09:38.061406 core/blockchain.go:959] imported 1 block(s) (0 queued 0 ignored) including 0 txs in 8.141851ms. #1133511 [140a530f / 140a530f]
I0615 02:09:38.061848 miner/worker.go:555] commit new work on block 1133512 with 0 txs & 0 uncles. Took 210.852µs
> eth.mining
true
> web3.fromWei(eth.getBalance(eth.accounts[0]).toNumber(), "ether")
"28.902244797526348"
En una ventana separada, ejecute top
desde su línea de comando y debería ver geth
utilizar 100+% de CPU
Estoy usando el código fuente que aparece en Implementar el contrato de Greeter a través de geth CLI no se está registrando en mi cadena de bloques privada .
> 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; } }'
undefined
> var greeterCompiled = web3.eth.compile.solidity(greeterSource)
I0615 02:16:00.290143 common/compiler/solidity.go:114] solc, the solidity compiler commandline interface
Version: 0.3.4-0/RelWithDebInfo-Linux/g++/Interpreter
path: /usr/bin/solc
undefined
Veamos la información compilada:
> greeterCompiled
{
greeter: {
code: "0x606060405260405161023e38038061023e8339810160405280510160008054600160a060020a031916331790558060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10609f57805160ff19168380011785555b50608e9291505b8082111560cc57600081558301607d565b50505061016e806100d06000396000f35b828001600101855582156076579182015b82811115607657825182600050559160200191906001019060b0565b509056606060405260e060020a600035046341c0e1b58114610026578063cfae321714610068575b005b6100246000543373ffffffffffffffffffffffffffffffffffffffff908116911614156101375760005473ffffffffffffffffffffffffffffffffffffffff16ff5b6100c9600060609081526001805460a06020601f6002600019610100868816150201909416939093049283018190040281016040526080828152929190828280156101645780601f1061013957610100808354040283529160200191610164565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101295780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b565b820191906000526020600020905b81548152906001019060200180831161014757829003601f168201915b505050505090509056",
info: {
abiDefinition: [{...}, {...}, {...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc736903870",
compilerVersion: "0.3.4",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.4",
source: "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; } }",
userDoc: {
methods: {}
}
}
},
mortal: {
code: "0x606060405260008054600160a060020a03191633179055605c8060226000396000f3606060405260e060020a600035046341c0e1b58114601a575b005b60186000543373ffffffffffffffffffffffffffffffffffffffff90811691161415605a5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b56",
info: {
abiDefinition: [{...}, {...}],
compilerOptions: "--bin --abi --userdoc --devdoc --add-std --optimize -o /tmp/solc736903870",
compilerVersion: "0.3.4",
developerDoc: {
methods: {}
},
language: "Solidity",
languageVersion: "0.3.4",
source: "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; } }",
userDoc: {
methods: {}
}
}
}
}
Envía la transacción para insertar el código del contrato en la cadena de bloques. Verá que la transacción del contrato se ha extraído con éxito.
> var _greeting = "Hello World!"
undefined
> var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);
undefined
> 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);
}
}
})
Contract transaction send: TransactionHash: 0xcad6fb4afbf49a77fbd5622435ae010d0665b54f9eda18ad50858effe98f23f5 waiting to be mined...
undefined
Contract mined! Address: 0x170ab13569f1c8c9f99918b7f220ce88d1bc4beb
[object Object]
Ahora podemos llamar a la greet()
función:
> greeter.greet();
"Hello World!"
greeterCompiled
parece ser más extenso que antes. Necesito verificar.TypeError: Cannot access member 'info' of undefined
al hacer el pasovar greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);
Porque no lo agregaste.
greeter.at("0xXXXXXXXX")
Donde XXXX es la dirección que se muestra en la consola. Entonces, el saludador tendrá una dirección.
Si te perdiste el mensaje en la consola, aún puedes recuperarlo consultando la transacción. Si no conoce la dirección de la transacción, debe examinar la dirección de la cuenta. Puede hacerlo desde la consola o en el explorador Testnet, http://testnet.etherscan.io
greeter.at
me da error de tipo.Debe sincronizar la cadena de bloques de testnet y esperar el último bloque antes de ver su transacción
mira aquí https://testnet.etherscan.io
último bloque es BLOQUE 1128505
puede escribir eth.blockNumber debajo de su cliente geth para ver si está cerca de este bloque
disfrutar
billy m
privacidadisahumanright.eth
TMOTTM
TMOTTM
privacidadisahumanright.eth