Skip to content

tutorial for building your first ethereum smart contract πŸ’Ž

Notifications You must be signed in to change notification settings

ameru/smart-contracts-for-dummies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build your first Ethereum smart contract!

What you'll need:

Setting up your Blockchain Wallet on MetaMask

  1. On Ganache, select the "Quickstart ETH" option
  2. Copy your mnemonic into a text file (you'll need it for reference consistently throughout this project!)

mnemonic

  1. Fire up MetaMask, and choose "Import Wallet"
  2. Paste your mnemnic from Ganache into the "Seed phrase" blank, set up your own password of choice
  3. Your account should look like this: <MetaMask.png>

metamask

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.

  1. You can name your network anything you want, but make sure you copy and paste the URL from your "RPC Server" tab in Ganache.

RPC_URL

  1. The default Chain ID should be 1337, and you can enter "ETH" as the symbol for Ethereum. create_network

100_ETH

You're rich! Haha, just kidding. This is a test network.

Intro to Remix IDE and Solidity

  1. Remix IDE is an open-source tool to write Solidity contracts
  2. Written in JavaScript
  3. Fully functional web-based IDE (testing, debugging, deployment)
  4. In a web browser, go to https://remix.ethereum.org
  5. Under the "contracts" folder, right click on "new file", and name your new file "minimalist.sol" minimalist

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

  1. Use the keyword "contract" followed by the name. Your compiler should look like this now: pragma

  2. Click on the second tab, and click compile.minimalist.sol. You should see a green checkmark if your file compiles successfully. compile

  3. 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.

  4. Under "Deployed Contracts", you can click the copy icon to copy and paste your contract address in your browser. deploy

Add Methods to your Contract

  1. Add the following code to your file:

method

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. new_address

  1. 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. setmyvar

  2. 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)" modifier

About

tutorial for building your first ethereum smart contract πŸ’Ž

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published