Giter VIP home page Giter VIP logo

create-solidity-project's Introduction

Create Solidity Project

Generates a raw dependency project for developing smart contracts.

Create Solidity Project is tested on macOS and Linux.
If something doesn't work, file an issue.

Quick Steps

Setting up a normal project

$ npx create-solidity-project project-name

Setting up a typescript project

$ npx create-solidity-project project-name --template typescript

(npx comes with npm 5.2+ and higher, see instructions for older npm versions)

Known Issues

Why should one use raw dependencies instead of frameworks?

  1. In the current phase of blockchain development, most of the tools are well tested for basic features but complex utils might have bugs since less devs might have used them. Using a framework, with dependencies in which bugs are found and fixed more frequently results in receiving late updates in case a particular internal dependency breaks and needs update. Android OS users can relate with this, updates released directly from Google are available instantly to users in Pixel or Motorola, while for brands like Samsung releases OS with mod at after a delay. It's just a matter of choice of techies ;)
  2. Frameworks abstract inner functionality away from devs to make it smooth, but this results in lesser learnings of blockchain internals for beginner devs.

Things to consider

create-solidity-project is not a framework, it only copys basic files and installs raw dependencies, after that you are on your own. You will need to refer documentation of the particular dependency (links mentioned in created project's README) for any further hacking in your project. If you are a learner and want to hack into internals your workflow, you can give this a try. If you have any questions, you can shoot them to me.

If you are instead looking for abstraction (easy tasks become easier), this tool is NOT for that. Using some frameworks can be ideal for this requirement. Some of them: Truffle, Waffle.

If you are familiar with create-react-app, using smart contract frameworks can be similar to relying on magic done by react-scripts while few developers prefer to use with raw dependencies (with npm run eject) so they can hack into it.

Javascript project

Dependencies:

  • solc
  • ethers
  • mocha
  • ganache-core
  • fs-extra

File structure:

├── build // gets generated after: npm run compile
   └── SimpleStorage.json

├── contracts
   └── SimpleStorage.sol

├── test
   └── SimpleStorage.test.js

├── node_modules
├── compile.js // compiles if contract files changed
├── helpers.js
├── .gitignore
├── .gitattributes
├── README.md
└── package.json

Scripts:

  • npm run compile: compiles your contracts if they haven't already.
  • npm run test: compiles contracts and runs the test scripts.

Typescript project

Dependencies:

  • solc
  • ethers
  • mocha
  • ganache-core
  • fs-extra
  • ts-node
  • typescript
  • typechain
  • @typechain/ethers-v5
  • @types/node
  • @types/mocha
  • @types/fs-extra

File structure:

├── build // gets generated after: npm run compile
   ├── artifacts
      └── SimpleStorage.json // compiled contract
   └── typechain
       ├── SimpleStorage.d.ts // contract type definatinons
       └── SimpleStorageFactory.ts // contract factory (bytecode && abi)

├── contracts
   └── SimpleStorage.sol

├── test
   ├── suites
      ├── index.ts // test import file
      ├── Ganache.test.ts
      └── SimpleStorage.test.ts
   ├── utils
      ├── index.ts
      └── parseReceipt.ts // parses logs & contract internal txs
   ├── global.ts // declare global vars (common stuff across tests)
   ├── server.ts // start ganache server
   └── index.ts // grand test import file

├── node_modules
├── compile.ts // compiles if contract files changed
├── .gitignore
├── .gitattributes
├── README.md
└── package.json

Scripts:

  • npm run compile => compiles your contracts if they haven't already.
  • npm run test => compiles contracts and runs the test scripts.
  • npm run test:debug => runs tests in debug mode, this activates parseReceipt util to console log the contract events emitted and internal transactions executed.

Getting Started

  • npx csp new-project-name --template tsc.
  • Start by editing contracts/SimpleStorage.sol and test/SimpleStorage.test.js file. You can try adding methods to contract and access them using simpleStorageInstance.methodName() in test file.

Using parseReceipts to display the logs emitted and internal tx during the tests

// prints logs and internal txs if any occurred in DEBUG MODE
await parseReceipt(simpleStorageInstance.methodThatEmitsLogsOrInternalTxs());

To run tests in debug mode: npm run test:debug.

More details

  • This project uses ethers.js, a Complete Ethereum library with wallet implementation in JavaScript. This makes it a great alternative to web3.js. You will want to keep ethers.js documentation handy.
  • You can customise to a specific solc version by doing npm i [email protected], but it's not recommended. Note: [email protected].* will not work with this template, because it has a different compile.js structure. It is recommended that you upgrade your smart contract code to be able to be compiled by a [email protected].* and above compiler. You can check out breaking changes in 0.5.* and breaking changes in 0.6.*and upgrade your smart contracts accordingly.
  • If you wish to use web3.js instead, you can do it by uninstalling ethers.js using npm uninstall ethers, then you can install web3.js using npm i web3. Then you will have to change the tests files.

Acknowledgement

This tool is heavily inspired from facebook/create-react-app. Creators of this project are very much thankful to create-react-app's creators and contributors.

create-solidity-project's People

Contributors

pranjal1127 avatar snyk-bot avatar zemse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

create-solidity-project's Issues

Allow an option for using a github repository as a template

Get a github repo as user input, place repo's files as it is and parse it's package json and setup a project. Also configure the yarn/npm scene correctly, if user has yarn that yarn.lock if package.json then that. Along with change in project name and author name.

Also, I think a prompt to prevent doing a git commit could be helpful? Since this would be kindof experimental

Do not git commit when project created

  • Due to the simple storage contract, which is not part of the project. It is undesired to get something commited that u don't want in project's version control.
  • Also people can prefer different commit message style.

There should be a setup command for web3 js

Currently, ethers.js is installed default. But still many developers prefer web3.js.

It would be very helpful to have a command something like:

npx create-solidity-project my-project --web3js

This would setup a project with web3.js along with the test files worked with web3.js too.

If someone can contribute the test script with web3.js, we can add this option too.

Add info about design goals in the README

Raw thoughts:

  • Start working on a smart contract instantly with zero config.
  • Extremely customizable as per developer needs (point that differentiates csp and truffle)
  • always MIT

More can be added

Add functionality to compile only if contracts folder contents have been changed

When we do node compile.js && npm run test, first contracts are compiled then tests are run.

While development either we change contract code or change tests code. If we change contract code file both the commands should run, but if we change tests code, then only npm run test should be run. Compiling contracts again with no change in source code is a waste of time. So this can be improved.

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.