A light template, which is intended to get a Ethereum Smart Contracts Developer quickly started into developing Bug-free Smart Contracts.
- Start a fresh solidity project using this template through https://github.com/zemse/smart-solidity-template/generate.
- Clone your project using
git clone <repo-git-url>
in your projects folder. - Delete
SimpleStorage.sol
fromcontracts
folder. Create your smart contract file with it's appropriate name, e.g.Lottery.sol
. Please make sure that you are using the latest version of solidity in your smart contract in the first linepragma solidity 0.6.1
. - In the project directory, do
node compile.js
. This will compile your contract, show errors or warnings if any and will place the json files into a build folder. - In the
test
folder, you can rename the existingSimpleStorage.test.js
file by your contract name, e.g.Lottery.test.js
and refer to the contents for understanding to write tests. Run the tests by doingnpm run test
. - While developing smart contract, it's a good practice to write tests as you implement any new contract code.
- The command
npm run test
compiles your contracts if you made any changes and then runs tests.
- You can test deployment on testnets like
rinkeby
orkovan
. For deployment on mainnet, it is suggested to use Remix IDE for now. - To deploy all compiled contracts, do
node deploy.js deployall rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7
. - To deploy a specific contract, write it's JSON file name instead of deployall flag, e.g.
node deploy.js SimpleStorage_SimpleStorage.json rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7
. - If the contract requires constructor arguments, you can pass it by adding them after the command, e.g.
node deploy.js SimpleStorage_SimpleStorage.json rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7 "hello world"
.
- You can customise to a specific
solc
version by doingnpm 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].*
compiler. You can check out breaking changes in0.5.*
at https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html and upgrade your smart contracts accordingly. - This project uses
ethers.js
library in the tests. You can find docs at https://docs.ethers.io/ethers.js/html/. If you wish to useweb3.js
instead, you can do it by uninstallingethers.js
usingnpm uninstall ethers
, then you can installweb3.js
usingnpm i web3
. Then you will have to change the tests files.