Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Why does ethersjs not expose the contract address until deploy confirmation? #349

Open
kerzhner opened this issue Dec 7, 2018 · 2 comments

Comments

@kerzhner
Copy link
Contributor

kerzhner commented Dec 7, 2018

In theory, the contract address is known as soon as the deploy transaction is submitted.

@lalexgap
Copy link
Collaborator

lalexgap commented Dec 7, 2018

This might be due to the fact that we're using generic transactions to deploy the contract. It looks like the Contract API might support this https://docs.ethers.io/ethers.js/html/api-contract.html#deployment

@tomclose
Copy link
Contributor

tomclose commented Dec 7, 2018

You can get it with ethers - you just have to work a bit. This is how ethers does it itself:

deploy(...args: Array<any>): Promise<Contract> {

  // Get the deployment transaction (with optional overrides)
  let tx = this.getDeployTransaction(...args);

  // Send the deployment transaction
  return this.signer.sendTransaction(tx).then((tx) => {
    const contract = new Contract(getContractAddress(tx), this.interface, this.signer);
    defineReadOnly(contract, 'deployTransaction', tx);
    return contract;
  });,
};

which uses this method from utils:

// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
export function getContractAddress(transaction: { from: string, nonce: Arrayish | BigNumber | number }) {
    if (!transaction.from) { throw new Error('missing from address'); }
    var nonce = transaction.nonce;

    return getAddress('0x' + keccak256(encode([
        getAddress(transaction.from),
        stripZeros(hexlify(nonce))
    ])).substring(26));
}

We should be able to do the same in the transaction-sender.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants