DEV Community

loading...
Cover image for A easy way to start developing smart contract

A easy way to start developing smart contract

glaze
・3 min read

Feel tired to set up smart contract development environment? Tired of configuring hardhat and truffle? Try create-smart-contract.

It helps you set up Ethereum smart contract development environment and configuration with one command.

Quick start

// prerequesite
npm install truffle -g
// quick start
npx create-smart-contract my-contract
Enter fullscreen mode Exit fullscreen mode

What is included?

This scaffold installs and configures some useful frameworks and packages.

Included frameworks and its plugins

Included packages

Configuration file

  • .gitignore
  • .prettierrc
  • hardhat.config.js
  • slither.config.json
  • solcover.js
  • truffle-config.js

npm scripts

  • npm run test: Run tests under /test folder.
  • npm run doc: Generate docs based on doxygen.
  • npm run coverage: Generate code coverage configured by .solcover.js
  • npm run analyze Static analyze smart contracts configured by slither.config.json.Notice:You need install Slither by yourself

Customize

Development setup

git clone https://github.com/glazec/create-smart-contract.git
cd create-smart-contract
npm link
Enter fullscreen mode Exit fullscreen mode

Then create-smart-contract will point to your local version.

Customize dependencies

Modify installPackages in index.js.
For example, you only want to install hardhat.

const installPackages = () => {
    return new Promise(resolve => {
        console.log("\nInstalling hardhat\n".cyan)
        shell.exec(`npm install --save-dev hardhat`, () => {
            console.log("\nFinished installing packages\n".green)
            resolve()
        })
    })
}
Enter fullscreen mode Exit fullscreen mode

Customize templates

Add your template to templates/ folder.
Then add your your template into templates/templates.js.
For example, you would like to add .env.
You first put .env into templates/ and modify templates/templates.js. The keys of the exported dict will be the file name.

let fs = require('fs')
let path = require('path')
const gitIgnore = fs.readFileSync(path.resolve(__dirname, './gitignore'))
const solcover = fs.readFileSync(path.resolve(__dirname, './solcover.js'))
const slither = fs.readFileSync(path.resolve(__dirname, './slither.config.json'))
const hardhatConfig = fs.readFileSync(path.resolve(__dirname, './hardhat.config.js'))
const truffleConfig = fs.readFileSync(path.resolve(__dirname, './truffle-config.js'))
const prettier = fs.readFileSync(path.resolve(__dirname, './.prettierrc'))
const package = fs.readFileSync(path.resolve(__dirname, 'package.json'))
const env = fs.readFileSync(path.resolve(__dirname, '.env'))
module.exports = {
    '.gitignore': gitIgnore,
    'solcover.js': solcover,
    'slither.config.json': slither,
    'truffle-config.js': truffleConfig,
    'hardhat.config.js': hardhatConfig,
    '.prettierrc': prettier,
    'package.json': package,
    '.env': env
}

Enter fullscreen mode Exit fullscreen mode

Discussion (0)