GithubHelp home page GithubHelp logo

dethcrypto / truffle-typechain-example Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 8.0 77 KB

Example how to use Truffle suite with Typescript and Typechain

TypeScript 93.98% JavaScript 6.02%
truffle typescript typechain ethereum

truffle-typechain-example's Introduction

truffle-typechain-example

Deprecated. We moved examples to TypeChain repo: https://github.com/ethereum-ts/TypeChain/tree/master/examples

Example how to use Truffle suite with Typescript and Typechain

Usage:

Just run yarn generate to compile smartcontracts and generate initial TS wrappers for contracts. Then yarn test

Everytime you change contracts you need to run yarn generate.

Setup

  1. Install truffle-typings. — yarn add --dev truffle-typings
  2. Tweak truffle.js:
require("ts-node/register");

module.exports = {
  // this is required by truffle to find any ts test files
  test_file_extension_regexp: /.*\.ts$/,
};
  1. Install typechain — yarn add --dev typechain

  2. Add generate script in your package.json:

"scripts": {
    "generate": "truffle compile && typechain --target truffle './build/**/*.json'",
    "prepare": "yarn generate",
  }
  1. Everytime you change contracts you need to run yarn generate.

  2. Your migration functions should be typed as: Truffle.Migration and you sometimes need to make sure that they are treated as modules by tsc by adding: export {};.

  3. If you run tests with truffle test you might need to tweak your tsconfig.json, otherwise you get missing import errors like Cannot find name 'artifacts'. An example config is provided in this project.

  4. It's done! 🔥 Make sure to use .ts extension for everything

truffle-typechain-example's People

Contributors

krzkaczor avatar lsaether avatar miohtama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

truffle-typechain-example's Issues

No longer required to modify Truffle config to find .ts files

In the truffle-typechain-example README it says,

// this is required by truffle to find any ts test files
test_file_extension_regexp: /.*\.ts$/,

But from the Truffle docs, Truffle now supports tests saved as a .ts TypeScript file. (Source)

So I think that Tweak truffle.js step can be removed that from the README, right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.