I'm following Alan Buxton's tutorial, and am trying to go one step beyond and run it with a single command. but the contract's address and functions are still invisible, even after the contract is mined on my personal testnet, while in the script; however the object is fully populated after the script exits and I'm dropped into the console:
jcomeau@aspire:~$ geth --datadir ~/.ethtest0 --networkid 911657 --preload simple_test.geth console
INFO [04-01|12:33:46] Starting peer-to-peer node instance=Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1
INFO [04-01|12:33:46] Allocated cache and file handles database=/home/jcomeau/.ethtest0/geth/chaindata cache=128 handles=1024
INFO [04-01|12:33:46] Initialised chain configuration config="{ChainID: 1907 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Metropolis: <nil> Engine: unknown}"
INFO [04-01|12:33:46] Disk storage enabled for ethash caches dir=/home/jcomeau/.ethtest0/geth/ethash count=3
INFO [04-01|12:33:46] Disk storage enabled for ethash DAGs dir=/home/jcomeau/.ethash count=2
INFO [04-01|12:33:46] Initialising Ethereum protocol versions="[63 62]" network=911657
INFO [04-01|12:33:46] Loaded most recent local header number=413 hash=19ef00…5a6b1f td=54502927
INFO [04-01|12:33:46] Loaded most recent local full block number=413 hash=19ef00…5a6b1f td=54502927
INFO [04-01|12:33:46] Loaded most recent local fast block number=413 hash=19ef00…5a6b1f td=54502927
WARN [04-01|12:33:46] Blockchain not empty, fast sync disabled
INFO [04-01|12:33:46] Starting P2P networking
INFO [04-01|12:33:48] UDP listener up self=enode://199436ddf39880a2ee4a9ab3b0a7e8f51a2cf4d8f9a7863cee196e2498bd8be3d3c254d614b00530aaaf85f147c0c12acedb9239fcde2ba43ab1ae78e688d546@[::]:30303
INFO [04-01|12:33:48] RLPx listener up self=enode://199436ddf39880a2ee4a9ab3b0a7e8f51a2cf4d8f9a7863cee196e2498bd8be3d3c254d614b00530aaaf85f147c0c12acedb9239fcde2ba43ab1ae78e688d546@[::]:30303
INFO [04-01|12:33:48] IPC endpoint opened: /home/jcomeau/.ethtest0/geth.ipc
Unlock account 0x51344909b248a7ec9469b13161c0afae4ed4f001
Passphrase:
INFO [04-01|12:33:57] Submitted contract creation fullhash=0x198fca704efd39eddf9bade902e0eed81b327fa0436627c14ea3c88884be3d62 contract=0x837fd4a24ca76786c0e722cd443fec5ebcb37313
simple.transactionHash: 0x198fca704efd39eddf9bade902e0eed81b327fa0436627c14ea3c88884be3d62
INFO [04-01|12:33:57] Updated mining threads threads=2
INFO [04-01|12:33:57] Transaction pool price threshold updated price=18000000000
INFO [04-01|12:33:57] Starting mining operation
INFO [04-01|12:33:57] Commit new mining work number=414 txs=1 uncles=0 elapsed=2.217ms
INFO [04-01|12:38:52] Successfully sealed new block number=414 hash=b81df0…0279c9
INFO [04-01|12:38:52] 🔨 mined potential block number=414 hash=b81df0…0279c9
INFO [04-01|12:38:52] Commit new mining work number=415 txs=0 uncles=0 elapsed=1.229ms
simple.address: undefined
simple: {"_eth":{"_requestManager":{"polls":{"0x51ec59128e39d6ca54d1d22b0861a337":{"data":{"method":"eth_getFilterChanges","params":["0x51ec59128e39d6ca54d1d22b0861a337"]},"id":"0x51ec59128e39d6ca54d1d22b0861a337"}},"provider":{},"timeout":{}},"accounts":["0x51344909b248a7ec9469b13161c0afae4ed4f001","0xc652252b98dc81d83757f4ba577033838cbc63aa"],"blockNumber":414,"coinbase":"0x51344909b248a7ec9469b13161c0afae4ed4f001","compile":{},"gasPrice":"18000000000","hashrate":0,"mining":false,"pendingTransactions":[],"protocolVersion":"0x3f","syncing":false},"abi":[{"constant":false,"inputs":[{"name":"_a","type":"uint256"},{"name":"_b","type":"uint256"}],"name":"multiply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_a","type":"uint256"},{"name":"_b","type":"uint256"}],"name":"arithmetics","outputs":[{"name":"o_sum","type":"uint256"},{"name":"o_product","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}],"transactionHash":"0x198fca704efd39eddf9bade902e0eed81b327fa0436627c14ea3c88884be3d62"}
Welcome to the Geth JavaScript console!
instance: Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1
coinbase: 0x51344909b248a7ec9469b13161c0afae4ed4f001
at block: 414 (Sun, 01 Apr 2018 12:33:57 PDT)
datadir: /home/jcomeau/.ethtest0
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
> simple
{
abi: [{
constant: false,
inputs: [{...}, {...}],
name: "multiply",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: false,
inputs: [{...}, {...}],
name: "arithmetics",
outputs: [{...}, {...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}],
address: "0x837fd4a24ca76786c0e722cd443fec5ebcb37313",
transactionHash: "0x198fca704efd39eddf9bade902e0eed81b327fa0436627c14ea3c88884be3d62",
allEvents: function(),
arithmetics: function(),
multiply: function()
}
> simple.arithmetics.call(5, 6)
[11, 30]
here is the test script:
loadScript("simple.abi")
loadScript("simple.bin")
console.log("simple.transactionHash: ", simple.transactionHash)
miner.start(2)
admin.sleepBlocks(1)
miner.stop()
console.log("simple.address: ", simple.address)
if (simple.address == undefined) console.log("simple: ", JSON.stringify(simple))
else console.log("simple.aritmethics.call(5, 6): ",
simple.arithmetics.call(5, 6))
could someone please explain why the address
and arithmetics
attributes aren't available in the script itself, and what I can do about it? thanks.