5

I'm getting a list of the last few blocks like described here.

Now I can't seem to get the address of each block or the associated contract, through web3.eth.getBlock. A lot gets returned, but no addresses. I'm getting the block through the index number, and not through the address.

I do get an address from a callback in a .watch function, after I triggered a transaction.

What I'd like to achieve is to derive some useful and readable information from the callback of .getBlock, all I have right now is the timestamp. And also the transactions Array is 0 every time, no matter what the transaction is. I've also tried getStorageAt which always returns 0x00 no matter which address or which position I request, this can't be normal behaviour? I am running testrpc, perhaps this has limited data returns?

Or am I trying to get the information from the wrong source? Since a block is not necessarily equivalent to a contract?

Cubedj
  • 363
  • 1
  • 2
  • 8

1 Answers1

4

Block #1 does not have any transaction. There are no transactions in blocks 1 to 46146 - see Error in download full data with Geth ( transaction field in Block is empty).

Try block 1757201. You should see the following:

> eth.getBlock(1757201)
{
  difficulty: 54831103175033,
  extraData: "0xd783010406844765746887676f312e342e32856c696e7578",
  gasLimit: 4712388,
  gasUsed: 3059685,
  hash: "0xec4cd4f70ab16718ada2795b0b24f2be6498f4fca3e0b6b79e045933814f56e7",
  logsBloom: "0x00000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000002000000000000000000000000000000000000000000000000002000000000000000000000000000000000",
  miner: "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
  nonce: "0x8b119d486f87adf5",
  number: 1757201,
  parentHash: "0xd4bd6a69b51d768950f683151e009410b74403f8dc2780bf03697e3a6e4919c7",
  receiptRoot: "0x23ed6181c74edbcd2b29aa317dc84d320788a2c98b818b5fc49c475ef1d5164a",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 10736,
  stateRoot: "0x857cd117a16db6661eee8256702aa6879ecceccdb05a13637bad147760762547",
  timestamp: 1466691328,
  totalDifficulty: 30162772625997950877,
  transactions: ["0xd5875cdc5dea095e713b2409d585bd713d7f67bf1f0a0143293c00dc3db187da", "0xb7f5a83267df37248b44a7204b974a89d5ee870f00e91b6b2858b0088f8ada68", "0xc0fdbd563a0e26966e2f9803729f22bcaf29f0e73df158ccb0868058ce103ef2", "0xb294881e48ed00fe449b9604a29bea78db19ff1dee845f0af26eb75546a0a2f0", "0x0dda4a0efb859327c4755c9610bfafd921647542a60cd4d7fab37a2a1ac74b01", "0xbec6c60e5092138f52d0437c67528459d6a727332022b3686f1bc0df171a4c92", "0x5a9941189e91c5b1a68f8efd7a63b4aa28cb0fc72365d6bd4b2fabedd70da984", "0x13b66d8a1ce8eec4492e070037670c993477371c895e43d6dc498bc5d36ef726", "0x3db1158457a8659d9b249b06ccac059358eb110f9f136f229f94afb76144efdb", "0x15aa6a7e18237f6011bf5660c7c7fcdad57b00e2bd1b83179ed75c3a4d0521d3", "0xec830f03d41367e31d27578f1d981f45377accf0526ed9a9bc691e83b64694c2", "0x1d975af035632721617103e05bc0a4f035d9885ba8d279915dd9dee182a6c794", "0xbe0fc22dd5c7d5330cd5987ee63080d272c5802c7fee508602daf0220f3617df", "0x8dc9ef3427b16c240e6d4e2f4e428db575d5b55a89d22a392f4a0efa43110036", "0xd64b8106cbf8cd61288b765504125f68f9a74666a7aa2187bf83ac2a97cb6efd", "0x000c56bb6b29a1230cbceb3dfc165e15c040be8e5fcf1cb0c62397525bf528c1", "0x096f1b0ed9b7741582ee065bc9c725df0dbd5081fce37f1758c78c96028faa92", "0xed8af8503bfa73b1f5f92135712ef09c71db6e8e5b1a83fc2a5cd6e0fec5639a", "0x1e881a3643f099d84f34c3d5d0aa155cf737ea5348902d2675dec054e803cd11", "0x0289d236f7f9d14b82bd174cf317533566314231cb64c79ef1ec5532638b737b", "0xfa05d618ff5946eec57cb4770daa10f1751fed90a274688eccff2cb82c7365b5", "0x65fd378aec19b1e5302a14fac44077f4df13d5859f3fd27c86931c8ca0e5d0bd"],
  transactionsRoot: "0xfe3316b06b1fad15e6e1c0e06ad2043213f36518f122ad6dff0293fe57d26d5f",
  uncles: []
}

And using the transaction hash for the first transaction, you can see the from and to addresses:

> eth.getTransaction("0xd5875cdc5dea095e713b2409d585bd713d7f67bf1f0a0143293c00dc3db187da")
{
  blockHash: "0xec4cd4f70ab16718ada2795b0b24f2be6498f4fca3e0b6b79e045933814f56e7",
  blockNumber: 1757201,
  from: "0x0b21002b890bf8a03db09cf6f4290b37d92adc90",
  gas: 21000,
  gasPrice: 20466997395,
  hash: "0xd5875cdc5dea095e713b2409d585bd713d7f67bf1f0a0143293c00dc3db187da",
  input: "0x",
  nonce: 10,
  to: "0xe7a84e176cde685ca2fb47aea022343b76c27cd7",
  transactionIndex: 0,
  value: 113883784656551848
}

Check out the script at https://ethereum.stackexchange.com/a/2936/1268 to get a listing of the transactions in a block.

If you want to get the address of a created contract, you will have to use the following function:

> eth.getTransactionReceipt("0xe9ebfecc2fa10100db51a4408d18193b3ac504584b51a4e55bdef1318f0a30f9")
{
  blockHash: "0x17fea357e1a1a514b45d45db586c272a7415f8eb8aeb4aa1dcaf87e56f34ca59",
  blockNumber: 1428757,
  contractAddress: "0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
  cumulativeGasUsed: 3711215,
  from: "0x793ea9692ada1900fbd0b80fffec6e431fe8b391",
  gasUsed: 3711215,
  logs: [],
  root: "6378bfd8a57b04af7b7d0875aa3c4e69bc0bfbb806637c4e05e39a6cb2012808",
  to: null,
  transactionHash: "0xe9ebfecc2fa10100db51a4408d18193b3ac504584b51a4e55bdef1318f0a30f9",
  transactionIndex: 0
}

This is the transaction that created The DAO contract.

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193