Categories

  • articles

Tags

  • solidity
  • cypto

This quick and dirty tutorial will show you how to create Ethereum Smart Contract project using truffle framework.

Installation

Installing node and npm, here is a great tutorial but most of you should already have this setup

Install truffle framework

npm install -g truffle

Creating the project

Create a folder to be used for the project files and and open terminal inside.

Initialize Truffle Framework - Creates the basic project layout

truffle init

Initialize npm

npm init -y

Creating a contract in the contracts folder

truffle create contract <ArtifactName>

Creating a contract test file in the tests folder

truffle create test <ArtifactName>

Usefull Pacakges

All these are optional but usefull for me

OpenZeppelin

OpenZeppelin is a great library of ethereum smart contracts

npm install -E openzeppelin-solidity

Truffle Flattener

truffle-flattener is a tool to create single contract without any imports. This is usefull for when you sending your contract for audit or you want to deploy.

npm install -g truffle-flattener

To run

truffle-flattener <solidity-files> > <output-file>

Solidity-Coverage

Solidity-Coverage is used to test code coverage of test cases

npm install --save-dev solidity-coverage

Configuration is done via a file .solcover.js in the root of the project.

  • port - Port to run testrpc on / have truffle connect to
  • copyNodeModules - Copies specific node_modules packages into the coverage environment. If you using OpenZeppelin this is going to be needed.
  • skipFiles - Contracts to be skipped
  • norpc - Prevent solidity-coverage from launching its own testrpc
module.exports = {
  port: 8555,
  copyPackages: ['openzeppelin-solidity'],
  skipFiles: ['Migrations.sol'],
  norpc: true
}

To run execute

./node_modules/.bin/solidity-coverage

Sources