1

Web3 JavaScript app API provides property defaultBlock. It is described in documentation:

This default block is used for the following methods (optionally you can override it by passing the defaultBlock parameter):
•web3.eth.getBalance()
•web3.eth.getCode()
•web3.eth.getTransactionCount()
•web3.eth.getStorageAt()
•web3.eth.call()
•contract.myMethod.call()
•contract.myMethod.estimateGas()

also is said that it defaults to latest Block and it's save to say it is possible to set it to another block. The impact of overriding the defaultBlock is not clear to me - is there an effect on my account balance or an effect on geth syncing or other effects?

1

It does not have any consequences. web3.eth.defaultBlock points the latest block on the blockchain.

web3.eth.defaultBlock equals to web3.eth.getBlock(web3.eth.defaultBlock).number which also equals to web3.eth.getBlock("latest").

> web3.eth.defaultBlock
"latest"
> web3.eth.getBlock(web3.eth.defaultBlock).number
1562543
> web3.eth.getBlock(web3.eth.defaultBlock) //web3.eth.getBlock(1562543)
{
  difficulty: 5438437,
  extraData: "0xd783010509846765746887676f312e372e31856c696e7578",
  gasLimit: 4712388,
  gasUsed: 0,
  hash: "0xefeeb4153760247284c54085a7c5c6364a4aeb7d37767e80056865a8039e7340",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  miner: "0xe4e10dcf8011a091979313de6931992174ba2885",
  mixHash: "0x1c234b7931a506f9b6c91a0b69efd94ece4c92b6452ce038034c53c67f5afd02",
  nonce: "0x100e55077a7f91a9",
  number: 1562543,
  parentHash: "0xc2b9e5b64c7ecc251068046683b7075055fecdf468f38d8c8269f264c7fc1f7d",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 538,
  stateRoot: "0xce276dbb172ab81952f789286a33c22dc5a34743be5698b035c9f4d82a0fd722",
  timestamp: 1505821321,
  totalDifficulty: 3341762256857,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}
0

Every block has a state. For example your balance at block 1 might have been 0 Ether but at block 2 you where sent 5 Ether so your balance at block 3 will be 5.

This also goes for smart contracts, you cannot affect the state of a smart contract in a previous block but you can call functions and get the result as it was at that block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.