Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Last active July 16, 2018 05:44
Show Gist options
  • Save Tanapruk/0962e9eb99901b2c7c444cfb76e0a552 to your computer and use it in GitHub Desktop.
Save Tanapruk/0962e9eb99901b2c7c444cfb76e0a552 to your computer and use it in GitHub Desktop.
Truffle Studies

Compile

run truffle compile

All files that end with .sol in /contracts are turned into .json files in /build/contracts.

Ganache

  • Ethereum Test Server

Default is http://127.0.0.1:9545

Truffle uses this pattern in creating folders/files

  • contracts/ Folder for Solidity contracts
  • migrations/ javascript files that help deploy contracts to Ethereum network.
  • test/ Folder for testing javascript, codes and contracts
  • truffle.js Truffle config files

Truffle

Solidity alone is a .sol file. You will need to find out how you will put your .sol file on ETH network. Problems occurs when you want to test run. Where to test? How about unit test? Truffle is your rescue.

  • Package Management
  • Smart contract compiler.
  • Test Framework.
  • Interactive console.

npm install -g truffle

Migration

javascript files that help deploy contracts to Ethereum network.

artifacts.require() is similar to import of javascripts or require of nodes.

Example,

var ContractOne = artifacts.require("ContractOne");
var ContractTwo = artifacts.require("ContractTwo");

Requirements

  • truffle requires you to have contracts/Migrations.sol contract, so that you can use migration feature of truffle.
  • deployer our hero object in doing migrations

Tidbits

  • accounts args are to take from web3.eth.getAccounts(). If you dont have any wallet connect like Ganache or metamask then you won't see this.
  • In case you dont want to redeploy your old contracts, you can pass {overwrite: false} as your last parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment