# Mining
It's time to mine (opens new window) a block by
yourself. In this level, you are asked to enable the mining on geth
while
setting its
coinbase (opens new window)
to your address. So, you can complete this level by mining a block,
which gives a reward to your address and is mined after this level's instance is created,
and submit its block number to contract.submit(blocknumber)
!
This is how you play with a geth
node:
$ ./geth-attach.sh
Welcome to the Geth JavaScript console!
instance: Geth/v1.10.25-stable/darwin-amd64/go1.19.1
coinbase: 0x40f0a5357d65ff7711d0647a4a1acdc574bec540
at block: 395 (Tue Nov 15 2022 01:41:38 GMT+0900 (KST))
datadir: /Users/taesoo/hive/exploit-smartcontract/node/data
modules: admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
To exit, press ctrl-d or type exit
>
Let's set its coinbase and start mining!
> miner.setEtherbase(eth.accounts[0])
true
> eth.coinbase
"0x40f0a5357d65ff7711d0647a4a1acdc574bec540"
> miner.start()
null
As stated here (opens new window), you can list
up the lastn
blocks that reward to your account after mining.
> function minedBlocks(lastn, addr) {
addrs = [];
if (!addr) {
addr = eth.coinbase
}
limit = eth.blockNumber - lastn
for (i = eth.blockNumber; i >= limit; i--) {
if (eth.getBlock(i).miner == addr) {
addrs.push(i)
}
}
return addrs
}
// scans the last 1000 blocks and returns the blocknumbers of blocks mined by your coinbase
// (more precisely blocks the mining reward for which is sent to your coinbase).
> minedBlocks(1000, eth.coinbase)
[352708, 352655, 352559]
Note that the terms, coinbase, miner and etherbase, are identical.
← ABI Raw Transaction →