Ethers.js: Cast contract instances to addresses

Created on 9 Feb 2021  路  3Comments  路  Source: ethers-io/ethers.js

Hi, sorry if this was discussed before. I searched a little but couldn't find anything.

I think it would make sense to be able to use contract instances as arguments when an address is expected. That is, instead of:

const myContract = await MyContract.deploy();
const anotherContract = await AnotherContract.deploy(myContract.address)

you could do:

const myContract = await MyContract.deploy();
const anotherContract = await AnotherContract.deploy(myContract)

Most helpful comment

Awesome! Yes, issue #1035 gave the original idea.

I'll close this now as it is on my local todo.txt. :)

Thanks! :)

All 3 comments

This isn鈥檛 in v5 and would change signatures in a possibly non-backwards compatible way, but in v6, there will be an Addressable (or similarly named) interface, which Signer and Contract will implement. And possibly a few other things. :)

Oh, nice. I didn't think about Signer also being supported, but makes sense!

I guess you can close this issue if v5 can't/won't have this, and it's already in the v6 roadmap.

Awesome! Yes, issue #1035 gave the original idea.

I'll close this now as it is on my local todo.txt. :)

Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings