-
Notifications
You must be signed in to change notification settings - Fork 29
/
getBalanceProof.js
63 lines (59 loc) · 1.82 KB
/
getBalanceProof.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { BlockHeader } = require('@ethereumjs/block');
const { Common } = require('@ethereumjs/common');
const Web3 = require('web3');
async function getBalanceProofAsync(web3, address, blockNumber) {
const proof = await web3.eth.getProof(address, [], blockNumber);
console.log(proof.accountProof);
}
async function getBlockHeaderAsync(web3, blockNumber) {
const block = await web3.eth.getBlock(blockNumber);
const chainId = await web3.eth.getChainId();
const {
parentHash,
sha3Uncles,
miner,
stateRoot,
transactionsRoot,
receiptsRoot,
logsBloom,
difficulty,
number,
gasLimit,
gasUsed,
timestamp,
extraData,
mixHash,
nonce,
baseFeePerGas,
} = block;
const header = BlockHeader.fromHeaderData(
{
parentHash,
uncleHash: sha3Uncles,
coinbase: miner,
stateRoot,
transactionsTrie: transactionsRoot,
receiptTrie: receiptsRoot,
logsBloom,
difficulty: '0x' + BigInt(difficulty).toString(16),
number,
gasLimit,
gasUsed,
timestamp,
extraData,
mixHash,
nonce,
baseFeePerGas,
},
{ common: new Common({ chain: chainId }), hardforkByBlockNumber: true }
);
const serialized = header.serialize().toString('hex');
console.log({ blockHeaderRLP: serialized, blockNumber: block.number, blockHash: block.hash });
}
(async () => {
const { RPC, ADDRESS, BLOCK } = process.env;
const web3 = new Web3(RPC);
const blockNumber = BLOCK || (await web3.eth.getBlockNumber() - 10);
await getBalanceProofAsync(web3, ADDRESS, blockNumber);
await getBlockHeaderAsync(web3, blockNumber);
})();