Codementor Events

How to develop smart contracts using Truffle 5.0

Published Sep 14, 2018Last updated Mar 12, 2019
How to develop smart contracts using Truffle 5.0

Good day! I am pleased to announce the first beta release of Truffle v5. With this release, I am excited to bring you some new features and improvements that will make your life easier.

What's included, you ask? Well, get ready to use whatever Solidity version you want (Truffle will even automatically download it for you.) Or how about an improved migrations system, which dry-runs by default and provides lots of information to understand what is going right or wrong. Maybe you've been waiting for Web3.js 1.0. Perhaps you're sick of typing .then() and want to use await in the console. Truffle v5 has all of this, and more!

If you're as excited as we are and can't wait, here's how to upgrade:

> npm uninstall -g truffle
> npm install -g truffle@beta

Bring your own compiler
It's now possible to have Truffle compile with:

any solc-js version listed at solc-bin. Specify the one you want and Truffle will get it for you.
a natively compiled solc binary (you'll need to install this yourself, links to help below).
dockerized solc from one of images published here. (You'll also need to pull down the docker image yourself but it's really easy.)

Configuration and use

Example network config

ropsten: {
  provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io`),
  network_id: 3,
  gas: 5500000,           // Default gas to send per transaction
  gasPrice: 10000000000,  // 10 gwei (default: 20 gwei)
  confirmations: 2,       // # of confs to wait between deployments. (default: 0)
  timeoutBlocks: 200,     // # of blocks before a deployment times out  (minimum/default: 50)
  skipDryRun: true        // Skip dry run before migrations? (default: false for public nets )
},

Example Migration using async / await

const One = artifacts.require("One");
const Two = artifacts.require("Two");

module.exports = async function(deployer) {
  await deployer.deploy(One);

  const one = await One.deployed();
  const value = await one.value();

  await deployer.deploy(Two, value);
};

43867960-3499922c-9b20-11e8-8553-589308a6cd61.gif

Please click Like button if you think it would be a help to your develop.
And if you have any unclear things about this, then please ask about it.
I will give you a clear answer.
Thank you for your reading.

Discover and read more posts from Nian Yadong
get started
post commentsBe the first to share your opinion
Show more replies