Customize OpenZeppelin CLI deploy script to assign environment variable upon deployment?

Is there a way I can customize the operation of ‘oz deploy’ a bit? I’d like to assign a contract’s new address to an environment variable automatically upon deployment. This would save several steps in my development workflow because every time I make changes to a contract and redeploy it I have to change the address in several places.

I realize I could use upgradaeble contracts and thus not need to worry about updating addresses in my code but I think that could open up a bunch of other problems and moreover - I’m not ready to tackle upgradeable contracts anyway.

Now that I think about it anymore I can easily enough set the environment variable myself, but it’d be easier if the deploy script did this for me! (edit: This might not be all that easy unless I find a tool or script that lets me change environment variables on the fly and get my running processes to to get the update. I don’t know enough about Linux for it to be a trivial task.)

1 Like

Hi @Janssen,

Welcome to the community :wave:.

As you are deploying regular (non-upgradeable contracts) you may want to look at using a script with Buidler ( or a migrations script with Truffle ( Either would likely give you the flexibility that you need.

With Truffle, you could then use the Truffle environment to get the address you are using with .deployed(). (

Feel free to ask all the questions that you need.

Okay, thank you for your response! (I am really impressed with the support offered by the OZ team. It’s not common!

1 Like