Importing Existing Smart Contracts using Remix

mbvissers.eth
Quick Programming
Published in
3 min readNov 16, 2021

Import a Smart Contract and interact with it using Remix’s GUI.

Photo by Aleksi Räisä on Unsplash

Smart contracts are fairly easy to test using Remix during development, however, once you’ve deployed it, the only way to interact with the contract is by writing scripts, webpages, or using a tool such as Truffle. Or is it?

If you own the code and compile a contract to the exact same bytecode, you can import a smart contract by address, instead of redeploying it to continue testing. Let’s take a look at how to do this.

The Smart Contract

For this article, I’m not going to dive deeper into deploying or creating smart contracts. We just need to have some things clear before we try to import it at a later time on Remix.

  • You need to keep the exact code you used to deploy it to a testnet or mainnet.
  • You need to remember the compilation setting you’ve used.
  • The address of the smart contract.

If you have both, we can continue.

Importing the Smart Contract

With all the data from the previous chapter, we first need to add a new file (if you don’t have it already) with all the code of the contract you want to import.

So, create a new file and copy-paste the code of your existing and published smart contract. Give it a nice name, preferably the name of the existing contract.

Compile the contract as you normally would, but remember to use the same properties and settings as the deployed version.

Once it’s compiled, go to the next tab, and select injected web3 , and be sure to be on the same network as the deployed contract. Whether it’s Rinkeby or a mainnet.

At the At address button, next to it in the text field, paste the address of the contract and click the button. The contract should now be loaded below it.

You should now be able to interact with the contract.

Conclusion

A quick little tutorial on connecting an existing contract with Remix. You might not need to ever do this, but it might save some headache when you need to connect to a contract when a certain script isn’t yet deployed.

Thank you so much for reading and have an exquisite day.

Support me by supporting Medium and becoming a member. It helps me out a lot, it won’t cost you extra, and you can read as many Medium articles as you like!

Follow me on Twitter to keep up with me.

Check out my latest NFT collection here.

--

--

mbvissers.eth
Quick Programming

I occasionally write about programming. Follow me on Twitter @0xmbvissers