How to setup truffle on macOS
Information
Truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life
as an Ethereum developer easier.
Information about truffle, see: https://github.com/trufflesuite/truffle
Truffle commands, see: http://truffleframework.com/docs/advanced/commands
For this tutorial you need to have a running ethereum node, for example testrpc.
Operating system used
macOS 10.12 Sierra
Software prerequisites
Node.js
Procedure
- Make sure you have access to a running ethereum node, for example testrpc
By default testrpc listens to http://localhost:8545.
To start a stopped testrpc docker container, type: docker start CONTAINERID
- I have the following versions installed:
Type: node -v (version = 8.0.0)
Type: npm -v (version = 5.0.3)
- Install truffle, type: npm install -g truffle
Version 3.2.5 installed.
Show all installed npm packages, type: npm list -g --depth=0
- Create a truffle project, type: mkdir ~/ethdemos
Type: cd ~/ethdemos
- Create a truffle environment with default set of contracts and tests, type: truffle init
You will see the following:
Downloading project...
Project initialized.
Documentation: http://truffleframework.com/docs
Commands:
Compile: truffle compile
Migrate: truffle migrate
Test: truffle test
- Truffle creates the following:
- contracts
Directory where Truffle expects to find solidity contracts.
- migrations
Directory to place scriptable deployment files.
- test
Location of test files for testing your application and contracts.
- truffle.js
your main Truffle configuration file.
- Compile all solidity files in the contracts folder.
Type: cd ~/ethdemos
Type: truffle compile
You will see the following:
Compiling ./contracts/ConvertLib.sol...
Compiling ./contracts/MetaCoin.sol...
Compiling ./contracts/Migrations.sol...
Writing artifacts to ./build/contracts
- Deploy the contracts in the testrpc node.
Type: truffle migrate
You will see the following:
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
Migrations: 0x3eab8380c69ba859c2cd57fc50592c9636f55dff
Saving successful migration to network...
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying ConvertLib...
ConvertLib: 0x8df9609b6c5a18176ae783dde08ce932d67ac2de
Linking ConvertLib to MetaCoin
Deploying MetaCoin...
MetaCoin: 0xb313cec73471c44bed2bbf900dcf013087a24085
Saving successful migration to network...
Saving artifacts...
- To execute all test scripts in the test folder.
Type: truffle test
You will see the following:
Using network 'development'.
Compiling ./contracts/ConvertLib.sol...
Compiling ./contracts/MetaCoin.sol...
Compiling ./test/TestMetacoin.sol...
Compiling truffle/Assert.sol...
Compiling truffle/DeployedAddresses.sol...
TestMetacoin
✓ testInitialBalanceUsingDeployedContract (172ms)
✓ testInitialBalanceWithNewMetaCoin (116ms)
Contract: MetaCoin
✓ should put 10000 MetaCoin in the first account (47ms)
✓ should call a function that depends on a linked library (78ms)
✓ should send coin correctly (162ms)
5 passing (929ms)
|