What you'll need:
- MetaMask chrome extension - download here: https://metamask.io/
- Ganache Personal ETH Blockchain Platform: https://www.trufflesuite.com/ganache
- On Ganache, select the "Quickstart ETH" option
- Copy your mnemonic into a text file (you'll need it for reference consistently throughout this project!)
- Fire up MetaMask, and choose "Import Wallet"
- Paste your mnemnic from Ganache into the "Seed phrase" blank, set up your own password of choice
- Your account should look like this: <MetaMask.png>
You'll want to make sure you're not sending ETH over the Main Net (the default setting) and instead create your own network for testing out your transactions. To do this, click "Custom RPC" under the networks tab on the upper right hand corner of your screen.
- You can name your network anything you want, but make sure you copy and paste the URL from your "RPC Server" tab in Ganache.
You're rich! Haha, just kidding. This is a test network.
- Remix IDE is an open-source tool to write Solidity contracts
- Written in JavaScript
- Fully functional web-based IDE (testing, debugging, deployment)
- In a web browser, go to https://remix.ethereum.org
- Under the "contracts" folder, right click on "new file", and name your new file "minimalist.sol"
Each file should start with the pragma line, which tells the compiler which version of Solidity to run The syntax follows semantic versioning - https://docs.npmis.com/misc/semver
-
Use the keyword "contract" followed by the name. Your compiler should look like this now:
-
Click on the second tab, and click compile.minimalist.sol. You should see a green checkmark if your file compiles successfully.
-
On the thrid tab, you can deploy your smart contract. Click "Deploy" and your terminal should show a green checkmark if your contract deploys successfully.
-
Under "Deployed Contracts", you can click the copy icon to copy and paste your contract address in your browser.
- Add the following code to your file:
The blue words are function types, the yellow words are the function methods, and the orange words are the arguments. "uint" stands for unsigned integer, 256 denotes its length. 2. Now compile and deploy your contract again. Notice how you get a new address when you deploy the contract? Think of the first address as version 1 on the blockchain, along with the second address for added functionality.
-
If you expand the second address, you'll see it has an orange function "setMyVar". You can call and pass arguments through here. Let's enter "10" into setMyVar. You've now set the state of myVariable to a value of 10.
-
Always define a visibility specifier (public) for your methods. There are also optional "pure" and "view" modifiers. Since you are returning something, your function header requires including "returns(type)"