tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
423 stars 271 forks source link

Contract Address Predicting #551

Closed whynotmarc closed 2 weeks ago

whynotmarc commented 3 weeks ago

Hey there, I will start off by saying sorry for creating an issue in here, but I am unsure where else to go.

I am struggling to find any method of predicting future contract addresses. Does TronWeb have a method for this, or is there any other way to accomplish this with Tron?

whynotmarc commented 2 weeks ago

@whynotmarc What are you trying to do ?

Trying to predict a future deployed contract address (the next contract I deploy specifically)

Satan-web3 commented 2 weeks ago

Please using TronWeb latest version or beta version. By using transactionBuilder.createSmartContract() method, you'll get the future deployed contract address before broadcasting.

whynotmarc commented 2 weeks ago

Please using TronWeb latest version or beta version. By using transactionBuilder.createSmartContract() method, you'll get the future deployed contract address before broadcasting.

Hmm okay, but what if the contract is deployed through another contract. So calling Contract A's function deployContract, deploys Contract B.

How would I predict the address of Contract B?

Satan-web3 commented 2 weeks ago

You can use the salt option of solidity. See more here.

whynotmarc commented 2 weeks ago

You can use the salt option of solidity. See more here.

But if the contract is already live?

To be more specific. If I am calling this function on Contract A and the contract is already deployed and doesn't have verified code. Meaning I'm unsure if it uses salt to create and what salt is next.

I know the internal logs of the tx returns the address as well as an event emitted.

But the main issue is getting/predicting the address of the contract deployed by Contract A.

whynotmarc commented 2 weeks ago

Ended up making changes to the client for the best method.