A repository for compiling, deploying and calling smart contracts using web3.js.
Inspired by Patrick Collins' blockchain course [1], I decided to recreate Python lessons with JavaScript.
This is Lesson 4: Web3 Simple Storage.
Run the commands below to clone the repository and install the requirements.
Note that you may need a different version of solc.js.
git clone git@github.com:imagobea/web3js-simple-storage.git
cd web3js-simple-storage.git
npm install
Also needed:
- Node.js
- Ganache for spinning a local blockchain
- An Ethereum blockchain provider, like Infura (plus an Ethereum account e.g. using Metamask, and some test Ether, e.g. from Rinkeby faucet)
I recommend watching the lesson on Youtube, but this is pretty much what covers:
The solc.js library is used to compile Solidity, hence it has to be compatible with the version of your contract. Update the package.json
file as needed before installing the requirements, or update these.
Place your contract into the contracts
folder. Update scripts/compile.js
as necessary. Run:
node -r dotenv/config scripts/compile.js
This will create a compiled_code.json
file at root. This includes:
- The contract bytecode, required for deployment
- The Application Binary Interface (ABI), required for contract interactions
Set up web3.js to use the Ethereum blockchain in JavaScript [2].
TBC
- Network and URL provider environment vars
- Environment vars management in general
- Better error handling and logging - a classic!
- Flexible scripts to allow faster interactions with contracts other than SimpleStorage.sol
- Explore alternative ways of creating and broadcasting signed transactions (see scripts/deploy_testnet.js, bottom)
- Improve deployment scripts for publishing verified contracts
[1] Solidity, Blockchain, and Smart Contract Course - GitHub