Stage 2: Token Deployment¶
Important
The following videos may make note of the use of something called “Docker” and “containers”, but do note that Docker has since been omitted. The same commands that are mentioned may be run directly on the machine without entering into the noted container.
- Start up your Ethereum node, ganache
- Back within your terminal window where the
npm start
command was run, create a new terminal window, or tab, to run your blockchainNote
While within the terminal window select File -> Open Terminal to create a new window.
To create a new tab from within a terminal window:
ctrl+shft+t
Example output: Result is a new empty terminal, in the same directory you were in.
adam@adam:~/Desktop/blg/wallet-template$
Then run the blockchain emulation with the below command:
ganache-cli
Example output:
# ganache-cli Ganache CLI v6.0.3 (ganache-core: 2.0.2) [...] Listening on localhost:8545
- Open the application’s code in the Sublime text editor, time to get to some coding…
- Open the Sublime text editor by clicking on the Sublime icon in the left dock.
- From within Sublime open the wallet-template folder. Click on
File
in the top left corner and selectOpen Folder...
in the menu. SelectDesktop/blg/wallet-template
to open, and we can get to coding!
Note
- A default, and required, initial migration script(src/migrations/1_initial_migration.js), has been included. Do not remove this script.
- Write the Deployment Script
- Create a new file in order to deploy the token,
src/migrations/2_deploy_contracts.js
- Simply right-click on the migrations directory and select
New File
from the drop down menu to create the new file.- Select
File
=>Save As
and then enter the name of the file:2_deploy_contracts.js
, click theSave
button in the bottom right corner.Time to add some code to this new file!
- Import the token’s artifacts, line 1
const Token = artifacts.require("./Token.sol");
Define the owner account, line 2 - Note that the
truffle migrate
command exposes theweb3
object globally which is connected to your ganache nodeand therefore has access to all of the default 10 accounts.
const owner = web3.eth.accounts[0];
- Utilize truffle’s deployer object in order to deploy an instance of the token, line 4-6 - This deployer is a utility that
truffle
provides within its framework to make sendingcontract creation
transactions as easy as the one line below! - This function will be exported so that it may be executed by thetruffle migrate
commandmodule.exports = deployer => { deployer.deploy(Token, { from: owner }); }Important
Don’t forget to save!
This may be done either by selecting
File
=>Save
or viactrl+s
on the keyboard.
- Deploy your Token
Important
Now back within your terminal window where the
truffle test
command was recently run…Ensure you are still in the
src
directory!truffle migrate --reset
- Example output:
# truffle migrate --reset Using network 'development'. Running migration: 1_initial_migration.js Deploying Migrations... ... 0x26ff3f480502a228f34363e938289c3164edf8bc49c75f5d6d9623a05da92dbf Migrations: 0x3e47fad1423cbf6bd97fee18ae2de546b0e9188a Saving successful migration to network... ... 0x19a7a819df452847f34815e2573765be8c26bac43b1c10d3b7528e6d952ac02c Saving artifacts... Running migration: 2_deploy_contracts.js Deploying Token... ... 0x4a69e7840d0f96067964fb515ffea1a04a98fc5759849d3308584af4770c8f7b Token: 0xd58c6b5e848d70fd94693a370045968c0bc762a7 Saving successful migration to network... ... 0xd1e9bef5f19bb37daa200d7e563f4fa438da60dbc349f408d1982f8626b3c202 Saving artifacts... #
Important
You just sent your first contract creation transaction via the truffle
framework, well done!
As above, the Token
contract has been created at address: 0xd58c6b5e848d70fd94693a370045968c0bc762a7
, note that yours will
almost certainly be created at a different address!
Also the Migrations
contract was created which is nothing to worry about but just a utility the truffle
framework uses to monitor
the status of your transactions.
If you have a look back at ganache and select on the Transactions
tab you will see the Contract Creation
transactions that were sent
and lots of other data too!