How To Deploy Multiple Smart Contracts Using Truffle

Complex migrations explained

Alex Roan
BlockCentric

--

Photo by Zan on Unsplash

This article is for developers who are new to Smart Contract development. If you don’t know where to start, learn how to deploy a Smart Contract with Truffle in 6 steps before reading on.

When running migrations, sometimes you’ll need to deploy more than one contract. Other times you might need to pass parameters to the constructor of a contract you’re deploying. Here’s how to tackle complex migrations with Truffle Suite.

Multiple Contracts

Truffle gives us a migrations/ folder to store our migration scripts. If you’ve gone through a few Truffle tutorials or the official documentation, you’ll notice that the folder comes prepopulated with a file named 1_initial_migration.js. That’s because, for Truffle migrations to work, this file needs to deploy the Migration contract to the Blockchain before any other migrations can be performed.

Truffle runs each migration file in ascending order, so the files should be named as such. Since 1_initial_migrations.js is already taken, our first custom migration should begin with ‘2_’. For example 2_deploy_contracts.js. This is where we can write migrations for our contracts.

--

--

Alex Roan
BlockCentric

CoFounder at Cyfrin. Previously: Chainlink Labs.