jacob-truffleboxtest v1.0.0
npm Truffle box
This is a boilerplate code to make your smart contract as an npm library using truffle-plugin-modularizer . It exports the json files in build/contracts/ and creates src/index.js. Then you will be able to use your contracts as an instance of truffle-contract. Finally, publish them onto the npm repository, and import into your applications.
See this to get more detail how truffle-plugin-modularize works.
Usage
Contract side
Create a directory to start your project
mkdir YourProject cd YourProjectUnbox
npm-truffle-boxnpx truffle unbox wanseob/npm-truffle-boxDevelop and test
npm run testConfigure your truffle-config.json
```javascript// truffle-config.js module.exports = { ..., plugins: 'truffle-plugin-modularizer' , modularizer: { // output: 'src/index.js', // target: 'build/contracts' // includeOnly: [], // networks: [] }, }
Modularize your smart contract as a node module. The following command will automatically generate the
src/index.jsfile which contains your smart contracts astruffle-contractinstancesnpm run modularizeConfigure your package.json
//package.json { "name": "Your project name", ..., "main": "src/index.js", ... }Deploy to npmnpm publish
Application side
install your module
$ cd /your/react/app/path $ npm install --save "your-project-name"Import contracts into your front-end application and init with web3 provider
```javascriptimport { SampleContract } from 'your-project-name'
web3 = window.web3
SampleContract(web3).deployed().then( async instance => { await instance.add(10) await instance.add(20) await instance.add(30) let values = await instance.getValues() console.log("Values: ", values) } )
Scripts
npm run testContracts: It runs test cases intest/directory for your smart contracts. This usestruffle testcommand.npm run testModule: It runs test cases inmoduleTest/to check the modularized output. It modularizes your contracts and create a temporal output filebuild/index.tmp.js. You should write Mocha test cases importing your smart contract from the temporal output file.npm run test: It tests both the contracts and the modularized output.npm run standard: It follows JS standard style.npm run ethlint: Lint your smart contracts.
If you don't prefer standard style and ethlint, remove "pre-commit" property from the package.json .
License
Contributors
7 years ago