1

Can anyone help ?

I am trying to listen for a new contract deployed. I thought that contracts were sent to the zero address which means its a new contract deployment, although this is not working. Maybe I am doing something wrong ?

            for _, tx := range block.Transactions() {

                zeroed := util.IsZeroAddress(tx.Hash().Hex())

                if zeroed {
                    fmt.Println("We have a zero address!!!!")
                    fmt.Println("header", header.Hash().Hex())
                    fmt.Println("tx", tx.Hash().Hex())
                }

The above doesn't seem to work so I am obviously doing something wrong.

I am listening for new headers, then getting the block and then finally the transactions.

Does anybody know how I can confirm that one of the transaction is a new contract deployment ?

Thanks in advance

1 Answer 1

0

First off, this wont cover all instances of contract creation. Many contracts are created this way, by omitting the to address (hence it being 0x00...00), but many are also created by other contracs using the CREATE/CREATE2 opcodes. Uniswap exchange contracts, for example, are created by another contract, and not by omitting the to address in a transaction

This specific method isn't working because you aren't checking if the to address is all zeros, you're checking if the transaction hash is zero. Change the following to be the equivalent that gets the to address of the transaction:

util.IsZeroAddress(tx.Hash().Hex())
1
  • 1
    wow! Thanks, yep that was it. Silly mistake on my part BUT also, I was waiting to get a pancakeswap (which i assume is similar to uniswap as it was a fork) - and yep- i never got a zero address BUT the actual To() was nil :-) I placed it into BSCScan and sure enough its a token - which is what I was looking for! Thank you for all your help. Commented May 27, 2021 at 13:53

Your Answer

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

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