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
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.
- Install
truffle-typings. —yarn add --dev truffle-typings - 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$/,
};
-
Install typechain —
yarn add --dev typechain -
Add
generatescript in your package.json:
"scripts": {
"generate": "truffle compile && typechain --target truffle './build/**/*.json'",
"prepare": "yarn generate",
}
-
Everytime you change contracts you need to run
yarn generate. -
Your migration functions should be typed as:
Truffle.Migrationand you sometimes need to make sure that they are treated as modules bytscby adding:export {};. -
If you run tests with
truffle testyou might need to tweak yourtsconfig.json, otherwise you get missing import errors likeCannot find name 'artifacts'. An example config is provided in this project. -
It's done! 🔥 Make sure to use
.tsextension for everything