0

I use the following code to request data from etherscan API

from etherscan import Etherscan
eth = Etherscan("API_KEY_HERE") # key in quotation marks


response = eth.get_normal_txs_by_address(address="0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a", startblock="8200000", endblock="18998125", sort="srt")
print(response)

output:

[{'blockNumber': '8202023', 'timeStamp': '1563819581', 'hash': '0x5afb8990f9ba7ecb7cb9ccc7c5522177f6d5e321ca18f070378ba416a71d8284', 'nonce': '62', 'blockHash': '0x6cd95e6b24fa9c5d8e33839890f379d8b91cad490b2639570f16fa06f58eaa3e', 'transactionIndex': '60', 'from': '0x19c16bfadf1e2412ec98afa694ee71a0ddcd309c', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '1000000000000000', 'gas': '21000', 'gasPrice': '4800000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '3894335', 'gasUsed': '21000', 'confirmations': '10796195', 'methodId': '0x', 'functionName': ''}, {'blockNumber': '11616713', 'timeStamp': '1610143998', 'hash': '0xbd633ba440d70d9132f17c9e34a64f9c0cb1fea014d927ae2fdcb2199de01c70', 'nonce': '23', 'blockHash': '0x5c5b750db80cf35e8fdc063503c4856824da5be440314ce9c98332f8edde33b7', 'transactionIndex': '236', 'from': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'to': '0xd26114cd6ee289accf82350c8d8487fedb8a0c07', 'value': '0', 'gas': '52346', 'gasPrice': '90000000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0xa9059cbb000000000000000000000000c88fe66bcc71cf840c6a9aae4892c07a38b9e6260000000000000000000000000000000000000000000000a69671228c57640000', 'contractAddress': '', 'cumulativeGasUsed': '10008235', 'gasUsed': '52346', 'confirmations': '7381505', 'methodId': '0xa9059cbb', 'functionName': 'transfer(address _to, uint256 _value)'}, {'blockNumber': '15559109', 'timeStamp': '1663488083', 'hash': '0x99d9d995301ed292388e345a49b307e9442b438337f3ab89a50256d9f74aea80', 'nonce': '21', 'blockHash': '0x6c8e678ee9310aed9cefb63bdf218b7bb28ed6ab3ae6659e1991491f18547cc7', 'transactionIndex': '131', 'from': '0xcc60d9a9555d5116a7beb059f5aac9524ece2981', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '999', 'gas': '21000', 'gasPrice': '3183407632', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '15304890', 'gasUsed': '21000', 'confirmations': '3439109', 'methodId': '0x', 'functionName': ''}]

I want only want to print the timestamp of the last transaction. In this case there are 3 transaction. But it can be thousands.

Expected output:

1663488083

1 Answer 1

1

One way to do it is to assign your output to the variable my_list

 my_list = [{'blockNumber': '8202023', 'timeStamp': '1563819581', 'hash': '0x5afb8990f9ba7ecb7cb9ccc7c5522177f6d5e321ca18f070378ba416a71d8284', 'nonce': '62', 'blockHash': '0x6cd95e6b24fa9c5d8e33839890f379d8b91cad490b2639570f16fa06f58eaa3e', 'transactionIndex': '60', 'from': '0x19c16bfadf1e2412ec98afa694ee71a0ddcd309c', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '1000000000000000', 'gas': '21000', 'gasPrice': '4800000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '3894335', 'gasUsed': '21000', 'confirmations': '10796195', 'methodId': '0x', 'functionName': ''}, {'blockNumber': '11616713', 'timeStamp': '1610143998', 'hash': '0xbd633ba440d70d9132f17c9e34a64f9c0cb1fea014d927ae2fdcb2199de01c70', 'nonce': '23', 'blockHash': '0x5c5b750db80cf35e8fdc063503c4856824da5be440314ce9c98332f8edde33b7', 'transactionIndex': '236', 'from': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'to': '0xd26114cd6ee289accf82350c8d8487fedb8a0c07', 'value': '0', 'gas': '52346', 'gasPrice': '90000000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0xa9059cbb000000000000000000000000c88fe66bcc71cf840c6a9aae4892c07a38b9e6260000000000000000000000000000000000000000000000a69671228c57640000', 'contractAddress': '', 'cumulativeGasUsed': '10008235', 'gasUsed': '52346', 'confirmations': '7381505', 'methodId': '0xa9059cbb', 'functionName': 'transfer(address _to, uint256 _value)'}, {'blockNumber': '15559109', 'timeStamp': '1663488083', 'hash': '0x99d9d995301ed292388e345a49b307e9442b438337f3ab89a50256d9f74aea80', 'nonce': '21', 'blockHash': '0x6c8e678ee9310aed9cefb63bdf218b7bb28ed6ab3ae6659e1991491f18547cc7', 'transactionIndex': '131', 'from': '0xcc60d9a9555d5116a7beb059f5aac9524ece2981', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '999', 'gas': '21000', 'gasPrice': '3183407632', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '15304890', 'gasUsed': '21000', 'confirmations': '3439109', 'methodId': '0x', 'functionName': ''}]

Then get the last item in the list and assign it to the variable des_ind

des_ind = my_list[-1]

Then you can access the timeStamp from the dict using

print(des_ind['timeStamp'])

Bringing it all together, it should look like this:

my_list = [{'blockNumber': '8202023', 'timeStamp': '1563819581', 'hash': '0x5afb8990f9ba7ecb7cb9ccc7c5522177f6d5e321ca18f070378ba416a71d8284', 'nonce': '62', 'blockHash': '0x6cd95e6b24fa9c5d8e33839890f379d8b91cad490b2639570f16fa06f58eaa3e', 'transactionIndex': '60', 'from': '0x19c16bfadf1e2412ec98afa694ee71a0ddcd309c', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '1000000000000000', 'gas': '21000', 'gasPrice': '4800000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '3894335', 'gasUsed': '21000', 'confirmations': '10796195', 'methodId': '0x', 'functionName': ''}, {'blockNumber': '11616713', 'timeStamp': '1610143998', 'hash': '0xbd633ba440d70d9132f17c9e34a64f9c0cb1fea014d927ae2fdcb2199de01c70', 'nonce': '23', 'blockHash': '0x5c5b750db80cf35e8fdc063503c4856824da5be440314ce9c98332f8edde33b7', 'transactionIndex': '236', 'from': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'to': '0xd26114cd6ee289accf82350c8d8487fedb8a0c07', 'value': '0', 'gas': '52346', 'gasPrice': '90000000000', 'isError': '0', 'txreceipt_status': '1', 'input': '0xa9059cbb000000000000000000000000c88fe66bcc71cf840c6a9aae4892c07a38b9e6260000000000000000000000000000000000000000000000a69671228c57640000', 'contractAddress': '', 'cumulativeGasUsed': '10008235', 'gasUsed': '52346', 'confirmations': '7381505', 'methodId': '0xa9059cbb', 'functionName': 'transfer(address _to, uint256 _value)'}, {'blockNumber': '15559109', 'timeStamp': '1663488083', 'hash': '0x99d9d995301ed292388e345a49b307e9442b438337f3ab89a50256d9f74aea80', 'nonce': '21', 'blockHash': '0x6c8e678ee9310aed9cefb63bdf218b7bb28ed6ab3ae6659e1991491f18547cc7', 'transactionIndex': '131', 'from': '0xcc60d9a9555d5116a7beb059f5aac9524ece2981', 'to': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', 'value': '999', 'gas': '21000', 'gasPrice': '3183407632', 'isError': '0', 'txreceipt_status': '1', 'input': '0x', 'contractAddress': '', 'cumulativeGasUsed': '15304890', 'gasUsed': '21000', 'confirmations': '3439109', 'methodId': '0x', 'functionName': ''}]
des_ind = my_list[-1]
print(des_ind['timeStamp'])

Output: 1663488083 as desired.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.