I have a web3J application that is supposed to deploy a contract (by calling a function on another contract) then listen for the contractCreatedEvent that is fired by the factoryContract and then call a function on the new contract.

ContractA = Factory Contract that deploys ContractB and sends EVENT
ContractB = Some Contract with function fuBar()

So I do the following:

Address contractB = event.address

Now my problem is, that both, the deploy as well as the fuBar transaction are mined in the same block and fuBar even has a higher position thus not executing a call on the new contract but rather on an address with no code (yet)

can someone explain what is happening here? why do i get the address/event before the contract is actually deployed and operable?

  • 1
    Could this be an async problem? I'm not familiar with web3j, but I'm not sure if your code is actually waiting for the event to return. Perhaps it does in some other code, but that's my first thought.
    – wtk219
    Jun 28 '18 at 15:31
  • @wtk219 the second transaction needs the Address of the created contract and gets this address from the event. and inspecting the transaction I see that it has the correct address
    – AKroell
    Jun 29 '18 at 8:44

Your Answer

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

Browse other questions tagged or ask your own question.