title | actions | requireLogin | material | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deploying Our Smart Contract |
|
true |
|
Great! That was the difficult part — actually deploying to Rinkeby is going to be straightforward. To do this, Truffle relies on something called a migration.
It sounds like a migration involves a lot of stuff moving around, but in practice, a migration is nothing more than a JavaScript file that tells Truffle how to modify the state of our smart contracts.
Obviously, the first migration will just deploy the smart contract. Some other migrations deploy a new version of the code to add features or fix bugs.
In a nutshell, migrations provide a convenient way to keep track of the changes you make to your code.
If you want to deploy more than one contract, a separate migration file must be created for each contract. Migrations are always executed in order- 1,2,3, etc.
In this lesson, we will deploy only to Rinkeby. Deployment to the main net would require real money to pay for the gas and, once deployed, we won't be able to modify the code. Hence, it's best to deploy to Rinkeby first, and thoroughly test the code.
Before doing the deployment, make sure there is enough Ether in your account. The easiest way to get Ether for testing purposes is through a service known as a faucet
. We recommend the Authenticated Faucet running on Rinkeby. Follow the instructions, and within a few minutes, your address will be credited with some Ether.
- Now that everything is set up, it's time to deploy to Rinkeby. To do so, run
truffle migrate --network rinkeby
in the terminal to the right. Note how migrations are being executed in order😉.
Note:
truffle deploy
is just an alias fortruffle migrate
. However, since our command-line interpreter is pretty basic, it won't consider the answer correct unless you're usingmigrate
.
Deployment to the main net is not complicated at all. Once the smart contract is tested, you'll only have to run: truffle migrate --network mainnet
. Don't forget that you'll have to pay for gas! We trust you'll be able to do it.
If everything goes well, you're going to see a response that's similar to the one to the right.