Deploying Contracts on a Local Blockchain with Truffle
Deploying Contracts on a Local Blockchain with Truffle#
Now that the smart contracts we wrote (including the one for the ERC-20 token), we are now ready to send our smart contracts to the Ethereum blockchain.
To do this, we can use another
Truffle script called
deploy. If we run
truffle deploy in the root folder of
erc-20-token, the contracts will be sent to the
ganche-cli instance that you have running.
Before we can run the
truffle deploy script, we will have to add scripts to the migrations folder we created in chapter 6.
erc-20-token should look like this now.
In the migrations folder, add
1_deploy_contracts.js. In this file, we will add very simple code to tell Truffle to deploy two tokens for us. The first thing we need to do is import the
Next we create a
module.exports function that will deploy the smart contract with the three parameters name of token, symbol of token and the decimal places required.
If you now run
truffle deploy (from the root folder,
erc-20-token) the scripts will send information to the
ganache-cli local blockchain we have running.
You will see both consoles (Truffle and Ganache) update as the script runs. The information in the two sections will correspond as well (i.e. as contracts get created on the blockchain (
ganache-cli), you will see the Truffle script capture that information.