Socket
Socket
Sign inDemoInstall

create-solidity-project

Package Overview
Dependencies
169
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-solidity-project

Set up a raw dependency Solidity Smart Contract Project with one command.


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
Ā 

Readme

Source

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)

Why use raw dependency?

  1. Using an umbrella package of 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.
  2. Umbrella package tools abstract inner functionality away from devs to make it smooth, but this results in lesser learnings of blockchain internals for beginner devs.

Should I use raw dependency project?

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 have used them. So umbrella package tools are comfortable for projects that use basic and well used features but one can give a thought if they want to work with raw dependencies.

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 a mod at a later date. It's just a matter of preference ;)

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 solc@0.5.10, but it's not recommended. Note: solc@0.4.* 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 solc@0.5.* 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.

FAQs

Last updated on 10 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc