Environment Setup
Environment setup details for the web3 portion of the Bnomial project
Last updated
Environment setup details for the web3 portion of the Bnomial project
Last updated
This page explains how to set up your development environment in order to work on the web3 part of bnomial.
The web3 code of Bnomial is currently hosted in a separate repository: . We may merge it with the in the future.
Developing and testing smart contracts locally is quite easy to setup. You can do this both in windows as well as Unix/Linux machines however both operating systems have it's own caveat's to look into and adapt the instructions as applicable
I use VS Code as IDE and I can recommend installing extension. GitHub Copilot understands Solidity as well, so make sure you have it activated if you have access to it. VS code can be installed in either Linux or windows as applicable.
If you already have a working nodejs installed in your environment, you can skip this. To install nodejs, you can use the following link.
The next step after cloning the repository is to install all the required npm
packages. This will install everything you need to compile, test and deploy smart contracts with Solidity.
This is pretty much everything you need to write, compile and test smart contracts locally. FYI, Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
npm run build
if everything is working fine you will see a successful compilation message
some users have faced the below error
This error may persist even if the above described solution is attempted, to work around this and to have a more stable execution environment, we recommend enabling windows sub system for Linux or WSL2 in your windows machine, so that you can take advantage of both the worlds.
To install /enable WSL2, you may refer to the link below
<< I am not sure what was reported, can be updated later>>
Executing npm build resulted in the below error, you can try the solutions listed in the article and one of them might work to resolve this issue
Tip: to access Unix file system from windows explorer, simply type \\wsl$ in your explorer bar and you will see the Unix home directory inside windows and allows drag and drop functionality, which makes it easier to move the files across.
Post hardhat installation, we can execute the project and check if everything is fine before attempting to work on specific issues.
To compile type
npm run build
after successful compile message, you can test it.
npm run test
and you will see results similar to the below screen capture
npm run coverage
npm run gas
The above commands are scripted into the package.json file which is reproduced below for better understanding (open the image in a new tab for better clarity)
If you want to deploy on the blockchain, there are some more things you need to do.
One important thing to consider is which network to use. The good thing is that this setup allows to easily deploy on any network in the Ethereum eco-system without chaining the code! You should also always the first test on a testnet (free of charge) before deploying to the mainnet (you need to pay the fee).
Some of the networks to consider:
Ethereum mainnet - the most popular blockchain for smart contracts, but gas fees are really high. You will easily pay hundreds of dollars for deploying a contract there.
Rinkeby testnet - one of the most popular testnets for Ethereum. Supported by OpenSea, which is nice if you are creating an NFT.
Polygon mainnet - Polygon is a Proof-of-Stack Layer 2 network running on top of Ethereum. The native token there is MATIC and gas fees are very low. Supported by OpenSea.
Mumbai testnet - the most used test network for Polygon. Supported by OpenSea.
Optimism and Arbitrum - alternative Layer 2 networks, which may be interesting for ERC-20 tokens.
You will also need some Ethereum or MATIC tokens to pay for the deployment gas fees. On the testnets you can use a faucet to get some free tokens:
You will need your private key in order to sign the deployment transaction. In Metamask, click the 3 dots in the upper right corner next to your account, choose "Account details" and then "Export private key".
Remember, never share your private key with anybody! Also, make sure you don't commit it to the repository!
Go to your application and in the upper right corner you will see a button called "View Key". After clicking it you will find the URL with the integrated
Also do not forget to change the network to Polygon Mumbai, by default the URL will point to Ethereum main network. You can change the network by clicking on Edit App and following instructions.
Creating an account is straight forward and adding a new API key is easy as well - see the screenshot below.
.env
fileNow you are finally ready to create your .env
file! Make sure you don't commit it to the repository. It is already ignored in .gitignore
, but still, be careful. You are now basically going to just copy/paste the keys from the accounts you just created.
You are now ready to deploy your smart contract!
A sample .env file will look like below
npm run deploy:mumbai
you will see a screen similar to below
The last and final step is to verify the contract which we will do next
npm run verify:mumbai --<<smart contract address as displayed above>>
Now we have completed deployment of smart contract "as is" basis and successful completion of all steps is a pre-requisite before you can start work on the Github issues.
You can verify your installation by switching to the bnomial folder in your local environment (after cloning from the repository () as indicated earlier and executing
You need an Ethereum wallet to deploy a smart contract to the blockchain - you can create one with . If you already have a wallet there, I recommend creating a second one for testing in order to reduce the risk of leaking your private key.
If you are going to work with Polygon and Mumbai (which we currently use), you may also need to add these networks in Metamask manually: .
Mumbai faucet:
Rinkeby faucet:
In order to deploy to the blockchain you need a node to connect to it. When you use a dApp this is done by the Metamask extension. However, we are going to deploy from a script, so we need an alternative. There are services that offer API for that like or .
First, head over to and create an account. After that, you need to create a new application, where you need to specify a name and most importantly the network you want to use.
In order to verify your smart contract after it is deployed, you will also need an API key for (or in case of Ethereum/Rinkeby). If you don't verify your contract with Polygonscan, you will not be able to see its code or interact with it.