Skip to content

BlockDevsUnited/truffle_tutorial

 
 

Repository files navigation

truffle_tutorial

A tutorial for setting up a development environment and using truffle the smart contract framework

First we need to install nodejs and some node packages


On an Apple Mac - follow these instructions

  • Open terminal
#First install the node version manager nvm
brew install nodejs

#The following commands may need "sudo" in front
sudo npm install -g truffle
sudo npm install -g ganache-cli
sudo npm install -g express

Using Windows 10 - follow these instructions
* [Download and Install nodejs](https://nodejs.org/en/download/) * Open power shell as administrator
npm install -g truffle
npm install -g ganache-cli
npm install -g express

On a Linux Distro - follow these instructions

#This is Ubuntu for example
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

#Install the npm modules
sudo npm install -g truffle
sudo npm install -g ganache-cli
sudo npm install -g express

Once you have these installed, you should be able to then setup / run a Ganache server and deploy some smart contacts to it.

Steps to deploy smart contracts

  • REMINDER You must have already installed the dependicies to deploy to ganache (A test blockchain) server
    1. Open your terminal and run this command. It should result in creating a series of wallet addresses and launch the server listener.

      1. ganache-cli -p 8545
    2. Open a NEW terminal and git clone this project in your Developer folder (or other working / project folder)

      1. git clone https://github.com/mullinat/truffle_tutorial.git
    3. cd into the truffleWorkspace directory

      1. cd truffle_tutorial
      2. cd truffleWorkspace
    4. Now compile the example smart contracts

      1. truffle compile
    5. Now deploy the example smart contracts

      1. truffle migrate --reset

ATTENTION - the following activities will RESET your MetaMask Acount. If you're already using MetaMask to manage your Ethereum Wallet, you're going to have to find and ensure you have your SEEDPHRASE before doing any of the following activities. Going forward with this tutorial is at your own risk and may cause loss of any tokens already attributed to your MetaMask Account. when in doubt - don't proceed!

With your Tuffle contracts successfully deployed, you are now ready to access them via a web browser. REMINDER: You must have MetaMask installed and set to your local machine as it's network. http://127.0.0.1:8545. If you don't know how to set the network to local node (read this support article on MetaMask.io) You'll have to add the seed phrase from the terminal where you launched ganache-cli and set a password for this to work.

Launching the Node Server to test the smart contracts

  • REMINDER You must have already enabled MetaMask to fully launch and test the smart contracts, not having that process complete will limit your ability to update the data into the Smart Contract.
    1. Open your web browser and navigate to http://localhost:3042
     View the source of that page in your web browser window
    
    1. Launch the Browser Console screen and try in the commands shown in the View Source of the page

Success

The commands should run and enable you to test your Truffle Smart Contract setup and view the data from the compiled contracts

About

A tutorial for the truffle smart contract framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 62.7%
  • JavaScript 28.5%
  • Shell 8.8%