0

I've successfully deployed a contract using

Optional<TransactionReceipt> receipt = Contract.deploy(...).send().getTransactionReceipt();

The receipt how ever doesn't return a timestamp. It returns the transaction hash and the blocknumber.

How would I use the web3j library to get the timestamp of the contract creation time?

2 Answers 2

0

You get the timestamp from the block (where the contract creation transaction was included).

let block = await web3.eth.getBlock(nr); let date = new Date(Number(block.timestamp) * 1000) 
Sign up to request clarification or add additional context in comments.

1 Comment

I need the syntax for the Java library implementation Web3j. It doesn't have a .getBlock method
0

If you have a transaction receipt, you can get a Date object as follows.

TransactionReceipt txnReceipt = ... ... EthBlock txnBlock = web3j.ethGetBlockByHash(txnReceipt.getBlockHash(),true).send(); long txnBlockTimestamp = txnBlock.getBlock().getTimestamp().longValueExact() * 1000; Date blockDate = new Date(txnBlockTimestamp); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.