Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

v5.0.0-beta.2 – Bento Box of Candy 🍱

Pre-release
Pre-release
Compare
Choose a tag to compare
@gnidan gnidan released this 21 Nov 17:26

Greetings, Truffle community! πŸ’¬

Here is the latest Truffle v5 beta release. We've got some exciting changes to share with you, including: Solidity v0.5.0, the new truffle run command, integration with the Vyper compiler, and an upgrade to Web3.js 1.0.0-beta.36 that enables struct parameters.

Hope you enjoy! πŸ˜‹


ℹ️ Note about earlier beta releases: These release notes are for the third Truffle v5 beta release. To learn more about the changes in Truffle v5, please see the earlier release notes:


How to Upgrade

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

Highlights

Or jump to the full changelog below.

Usage analytics

πŸ“‹ We've added an opt-in user setting to help make Truffle better by gathering anonymized usage statistics. Please enable this feature by running this command in your terminal:

truffle config --enable-analytics

It is important for us to be able to make informed decisions about future Truffle improvements, so we have focused on ensuring that there is no breach of privacy or loss of performance when using this feature.

When you enable this setting, Truffle will collect information about your version number, the commands you run, and whether commands succeed or fail.

To prevent all performance problems, Truffle sends metrics over the network in a background process that automatically exits after 5 seconds, so a slow internet connection won't get in the way.

Thank you! πŸ™‡

P.S. if you're one for scrutiny, feel free to see the two places in the code where metrics are gathered: when running a command and to report version and errors. You can also verify that these are the only places this code gets invoked via a good ol' GitHub search for the word analytics. πŸ˜‰

truffle run <command>

We're excited for our roadmap ahead to make Truffle support third-party plugins.
Truffle v5 offers the beginnings of this journey with a new command.

Creating a custom command plugin

  1. Implement the command as a Node module with a function as its default export.

    Example: hello.js
    /**
     * Outputs `Hello, World!` when running `truffle run hello`,
     * or `Hello, ${name}` when running `truffle run hello [name]`
     * @param {Config} config - A truffle-config object.
     * Has attributes like `truffle_directory`, `working_directory`, etc.
     * @param {(done|callback)} [done=done] - A done callback, or a normal callback.
     */
    module.exports = (config, done) => {
        // config._ has the command arguments.
        // config_[0] is the command name, e.g. "hello" here.
        // config_[1] starts remaining parameters.
        let name = config._.length > 1 ? config._[1] : 'World!';
        console.log(`Hello, ${name}`);
        done();
    }

  2. Define a `truffle-plugin.json` file to specify the command.

    Example: truffle-plugin.json
    {
      "commands": {
        "hello": "hello.js"
      }
    }
  3. Publish to NPM

    For example, publish truffle-plugin-hello

Plugin installation / usage

  1. Install the plugin from NPM.

    npm install --save truffle-plugin-hello
    
  2. Add a plugins section to your Truffle config.

    Example configuration
    module.exports = {
      /* ... rest of truffle-config */
      
      plugins: [
        "truffle-plugin-hello"
      ]
    }
  3. Run the command

    In the command line
    $ truffle run hello
    Hello, World!
    

Solidity v0.5.0

Truffle now ships Solidity v0.5.0 by default. There are a lot of breaking changes in this version, so you might want to take a look.

If you'd like to use Solidity v0.4.xx, you can still do so by specifying the version in your Truffle config.

See example configuration for using v0.4.25
module.exports = {
  /* ... rest of truffle-config ... */

  compilers: {
    solc: {
      version: "0.4.25"
      /* ... */
    }

    /* ... */
  }
}

For more information, please see the section on how to Bring Your Own Compiler in the beta.0 release notes.

Support for v0.5.0 is still experimental, so please let us know if anything is broken! βš— ️

Vyper support

Introducing support for the Vyper contract programming language! Truffle will now compile *.vy contracts in your contracts/ directory.

Note: Support for Vyper is still early, so there may be bugs. You'll have to install the Vyper compiler yourself. Please see the docs on Installing Vyper.

Thank you @evgeniuz for implementing this and thank you @vs77bb for funding a GitCoin bounty for this work.

Getting Started with Vyper

We've published a Truffle Box to help you get started. If you're curious about using Vyper for your smart contracts, or just want to test it out, you can run:

truffle unbox vyper-example

Let us know if you find anything wonky!

Structured function parameters

We've upgraded Truffle to use Web3.js v1.0.0-beta.36, which includes support for passing/returning structs in Solidity functions.

To use this, you'll have to include the experimental pragma line near the top of your contracts:

pragma experimental ABIEncoderV2;

This allows you to use complex function arguments and return values in Solidity and interact with the resulting contracts via truffle-contract's JS interface.

See example contract
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

contract Structs {
  struct Coord {
    uint x;
    uint y;
  }

  function swap(Coord memory coord)
    public
    pure
    returns (Coord memory)
  {
    Coord memory reversed = Coord({
      x: coord.y,
      y: coord.x
    });

    return reversed;
  }
}
See example test
const Structs = artifacts.require("Structs");

contract("Structs", (accounts) => {
  it("reverses coordinates", async () => {
    const instance = await Structs.deployed();

    const original = { x: 5, y: 8 };

    const reversed = await instance.swap(original, { from: accounts[0] });

    assert.equal(reversed.y, original.x);
    assert.equal(reversed.x, original.y);
  })
});

Full changelog

New Features

  • #1240 Write contracts in Vyper (thanks @evgeniuz!)
  • #1356 Opt-in usage analytics (please help make Truffle better!)
  • #1374 Add debugger reset command
  • #1385 Write tests in TypeScript
  • #1440 Add truffle run command for plugins

Enhancements

  • #1221 Add NatSpec output to artifacts (thanks @JamesLefrere!)
  • #1305 Re-add removed commands: truffle build and truffle watch
  • #1325 Update truffle debug error handling
  • #1327 Support precompiled contracts in debugger
  • #1337 Prevent debugger from automatically quitting at the end of a transaction
  • #1348 Make truffle develop configurable
  • #1372 Log Truffle version information on error
  • #1380 Allow configuring allowed_extensions for migrations (thanks @roderik!)
  • #1388 Provide config network "ganache" and use by default
  • #1446 Add support for STATICCALL in debugger

Bug Fixes

  • #1302 Fix error handling in truffle debug
  • #1314 When unboxing, look for truffle-box.json instead of truffle.js
  • #1330 Fix regex for detecting named Solidity imports
  • #1331 Support relative paths in *_directory config settings
  • #1335 Fix solc-js version caching in truffle compile
  • #1350 Add --compile flag to truffle exec's help
  • #1371 Fix undefined sourcePath in debugger
  • #1377 Fix truffle build clean bug
  • #1387 Fix truffle develop undefined bug
  • #1390 Fix truffle version utility bug
  • #1391 Fix undefined truffle version output
  • #1397 Fix compilerSupplier bug
  • #1399 Fix error message in truffle migrate (thanks @lrettig!)
  • #1411 Prevent sending deduped (false) events downstream. (thanks @m-schmoock)
  • #1417 Add missing support for web3.js 1.0 in truffle install
  • #1435 Use Solidity's own provided JS wrapper
  • #1444 Pass empty hexstring to web3-eth-abi's abi.decodeLog instead of 0x

Dependency Updates

  • #1378 Upgrade truffle-hdwallet-provider to use web3 v1.0.0-beta.33
  • #1404 Update truffle-hdwallet-provider dependencies & add webpack config
  • #1409 Upgrade web3.js to v1.0.0-beta.36
  • #1430 Replace chokidar with sane for truffle watch
  • #1431 Don't bundle ethers in truffle-contract
  • #1433 Upgrade solc to v0.5.0 (thanks @jchancehud for the handy upgrade script!)

Internal Improvements

  • #1344 Create new CONTRIBUTING.md file (thanks @maxme!)
  • #1363 Enable eslint and prettier for static analysis and automatic code formatting
  • #1368 Add truffle-hdwallet-provider to monorepo
  • #1379 Add new package truffle-sawtooth-seth-provider
  • #1395 Fix tests for user-level mnemonics
  • #1398 Fix code coverage reporting integration
  • #1405 Upgrade lerna to ^3.4.3
  • #1406 Add missing devDependencies to fix an error on Node v11
  • #1412 Integrate Stale to automatically prune stale issues and pull requests
  • #1413 Fix geth build on Travis
  • #1425 Improve cleanup behavior for test sandboxes
  • #1428 Replace ID system for variables assignments in debugger
  • #1434 Fix CI build after Solidity v0.5.0 release
  • #1438 Fix href for Truffle logo in README
  • #1439 Update codebase for default Solidity v0.5.0

What's Next

This beta marks Truffle v5 as feature complete. From here, we plan to focus on stability in order to bring Truffle v5 out of beta and into the hands of users as a full release.

Thank you for the continued support and for all of your contributions to this project. We welcome your feedback and are excited to make Truffle v5 the best version of Truffle yet.