Your contract runs perfectly on my private blockchain using geth
and Browser Solidity that I downloaded to run locally and connect to geth
on http://localhost:8545 .
Deployment And Execution In Browser Solidity
Here is a screen showing the deployment ("Create") of the contract and the execution of setTrue(...)
using 43,324 gas and the event result true
:
Here is a screen showing the execution of getValue(...)
using 22,901 gas and the second event result true
:
Here is a screen showing the execution of setAddr()
using 27,867 gas and the third event result true
:
Deployment And Executing In Geth Using Browser Solidity Generated Code
Following is the code from the Web3 Deploy box in Browser Solidity:
var setadtContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"getValue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"setTrue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"bool"}],"name":"Print","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"address"}],"name":"PrintAddr","type":"event"}]);
var setadt = setadtContract.new(
{
from: web3.eth.accounts[0],
data: '0x6060604052610276806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480630ff4c91614610052578063975d711c1461006f5780639b8be4ee1461008c5761004d565b610002565b346100025761006d60048080359060200190919050506100a0565b005b346100025761008a6004808035906020019091905050610100565b005b346100025761009e60048050506101be565b005b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b600015156004600050600083815260200190815260200160002060009054906101000a900460ff161515141561015e5760016004600050600083815260200190815260200160002060006101000a81548160ff021916908302179055505b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b6001600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908302179055507f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b56',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
Here are the results of pasting the code above into the geth
console:
> var setadtContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"getValue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"key","type":"uint256"}],"name":"setTrue","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"anonymous":fa
undefined
>
...
......
...... data: '0x6060604052610276806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480630ff4c91614610052578063975d711c1461006f5780639b8be4ee1461008c5761004d565b610002565b346100025761006d60048080359060200190919050506100a0565b005b346100025761008a6004808035906020019091905050610100565b005b346100025761009e60048050506101be565b005b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b600015156004600050600083815260200190815260200160002060009054906101000a900460ff161515141561015e5760016004600050600083815260200190815260200160002060006101000a81548160ff021916908302179055505b7f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36004600050600083815260200190815260200160002060009054906101000a900460ff1660405180821515815260200191505060405180910390a15b50565b6001600360005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908302179055507f2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b36003600050
......
......
......
......
.........
.........
...... })
I0111 13:29:52.055310 internal/ethapi/api.go:1045] Tx(0x30eedc837b40897b7ec5ac914b30bed3307333dcba12e70d4840b7e0bd8d5c86) created: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
null [object Object]
undefined
> I0111 13:29:54.085918 miner/unconfirmed.go:105] 🔗 mined block #4704 [6c46e8d2…] reached canonical chain
I0111 13:29:54.085955 miner/unconfirmed.go:83] 🔨 mined potential block #4709 [6cc54975…], waiting for 5 blocks to confirm
I0111 13:29:54.087158 miner/worker.go:516] commit new work on block 4710 with 1 txs & 0 uncles. Took 1.210405ms
I0111 13:29:57.645780 miner/unconfirmed.go:105] 🔗 mined block #4705 [c9b78f22…] reached canonical chain
I0111 13:29:57.645928 miner/unconfirmed.go:83] 🔨 mined potential block #4710 [54b88d79…], waiting for 5 blocks to confirm
I0111 13:29:57.646092 miner/worker.go:516] commit new work on block 4711 with 0 txs & 0 uncles. Took 336.529µs
null [object Object]
Contract mined! address: 0x4ebb8365205f6096decbe0fcfcae91db164359bc transactionHash: 0x30eedc837b40897b7ec5ac914b30bed3307333dcba12e70d4840b7e0bd8d5c86
Here's the execution of setTrue(...)
in geth
:
> var tx = setadt.setTrue(1234, {from: eth.accounts[0]});
I0111 13:37:01.968067 internal/ethapi/api.go:1047] Tx(0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2) to: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
...
> eth.getTransactionReceipt(tx)
{
blockHash: "0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c",
blockNumber: 4771,
contractAddress: null,
cumulativeGasUsed: 43324,
from: "0x000d1009bd8f0b1301cc5edc28ed1222a3ce671e",
gasUsed: 43324,
logs: [{
address: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
blockHash: "0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c",
blockNumber: 4771,
data: "0x0000000000000000000000000000000000000000000000000000000000000001",
logIndex: 0,
removed: false,
topics: ["0x2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3"],
transactionHash: "0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2",
transactionIndex: 0
}],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000001000000000000",
root: "0x06937bb7d67fd4a8e18ab013d76218ffab8c7d339f71f4f3bace02e8b0e56e1b",
to: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
transactionHash: "0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2",
transactionIndex: 0
}
Let's retrieve the event log information, where you can see the true
result:
var printEvent = setadt.Print({}, {fromBlock: 0, toBlock: 'latest'});
printEvent.watch(function(error, result){
console.log(JSON.stringify(result));
});
...
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c","blockNumber":4771,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2","transactionIndex":0}
And here is the execution of setAddr()
and the resulting events:
> var tx2 = setadt.setAddr({from: eth.accounts[0]});
I0111 13:43:40.814744 internal/ethapi/api.go:1047] Tx(0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b) to: 0x4ebb8365205f6096decbe0fcfcae91db164359bc
...
> eth.getTransactionReceipt(tx2);
{
blockHash: "0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc",
blockNumber: 4811,
contractAddress: null,
cumulativeGasUsed: 42867,
from: "0x000d1009bd8f0b1301cc5edc28ed1222a3ce671e",
gasUsed: 42867,
logs: [{
address: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
blockHash: "0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc",
blockNumber: 4811,
data: "0x0000000000000000000000000000000000000000000000000000000000000001",
logIndex: 0,
removed: false,
topics: ["0x2b3980e1f246a34892c233a6b281a346c73168eed33a17c643f090ce730156b3"],
transactionHash: "0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b",
transactionIndex: 0
}],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000001000000000000",
root: "0xea4839d4e6a4f4cb0873506bb57cc566f38833ed3593f4e02a0c6e4cf55cc726",
to: "0x4ebb8365205f6096decbe0fcfcae91db164359bc",
transactionHash: "0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b",
transactionIndex: 0
}
> var printEvent = setadt.Print({}, {fromBlock: 0, toBlock: 'latest'});
undefined
> printEvent.watch(function(error, result){
console.log(JSON.stringify(result));
});
...
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0x479f7ee50c7568c92e48b1dbdcfe6f90e6e349ade6f9148abb1f7630f9954f0c","blockNumber":4771,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xcbca2eedeaab28b3447648651b3b18118e644bbcb48c5fb4923fef52d76102b2","transactionIndex":0}
{"address":"0x4ebb8365205f6096decbe0fcfcae91db164359bc","args":{"":true},"blockHash":"0xf5e9060cffa08aa76ed14f978e34412aa57d3fa459a178e50498c62b2e8d54dc","blockNumber":4811,"event":"Print","logIndex":0,"removed":false,"transactionHash":"0xa7317bc32128513df91aa45da6ec583b78904275d55457e1f8651b203d2c6c7b","transactionIndex":0}