Yooooo!! Here, I am going to show you how to write, compile and deploy a solidity smart contract on the Rinkeby Test Network. So lets go!!
Watch the video version on Vimeo >>> here
Table of contents
- What is a smart contract?
- What is solidity and its uses?
- What is the best online solidity IDE?
- Writing and Compiling a smart contract.
- Deploying a smart contract.
- Installing Metamask
- How to get some Ethereum for the Rinkeby test network
- Deploying to Rinkeby test network using Injected Web 3
What is a smart contract?
A smart contract is a computer program or transaction protocol that is designed to automate the execution, control, and documentation of legally significant events and activities in accordance with the conditions of a contract or agreement.
The decrease of the need for trusted intermediaries, arbitration and enforcement costs, fraud losses, and purposeful and inadvertent exceptions are all goals of smart contracts.
Smart contracts eliminate the requirement for a centralized system, legal system, or external enforcement mechanism to carry out trustworthy trades and agreements between distant, anonymous participants.
What is solidity and its uses?
Solidity is an object-oriented programming language designed exclusively for building and developing smart contracts on Blockchain systems by the Ethereum Network team.
It's used to establish smart contracts in the blockchain system that apply business logic and produce a sequence of transaction records.
Solidity is a programming language that allows you to write machine-level code and compile it on the Ethereum Virtual Machine (EVM).
It is comparable to C and C++ in many ways and is relatively easy to learn and understand. A "main" in C, for example, is identical to a "contract" in Solidity.
What is the best online solidity IDE?
The best online solidity IDE can be found here. A remix Ethereum IDE with lots of cool features.
It is an IDE offered by remix that allows you to write, and smart contracts on the solidity programming language. It has a couple of functionalities which includes basic file explorer, ability to create new file, folders, an inbuilt compiler and a functionality to deploy your smart contracts.
Writing and Compiling a smart contract
To create a solidity file, go to the file explorer and click on it. This should load a couple of predefined files. Click the contracts folder and hit the file icon on the top to create a solidity file.
Name it anything of your choice in my case I used "ContractTus.sol"
Inside of your newly created solidity file, copy and paste the below code.
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
contract HelloWorld{
string greeting;
constructor(string memory _greeting) {
greeting = _greeting;
}
function getGreeting() public view returns (string memory){
return greeting;
}
function setGreet(string memory _greeting) public {
// string memory greet = _greeting;
greeting = _greeting;
}
}
//SPDX-License-Identifier: UNLICENSED
Here we are adding a commented license, its is necessary you add this else solidity compiler will complain.
pragma solidity ^0.8.7;
Here we are telling the compiler "Yo man, I am going to be using version 0.8.7 or higher for writing this smart contract. So you better know whats up. I won't say this again. Ya' heard?"
contract HelloWorld{...}
Here, we are creating a basic smart contract, think of this as a class in any programming language say Java or Python.
constructor(string memory _greeting) {
greeting = _greeting;
}
In this line, we are creating a constructor that gets called on deployment of this smart contract. We are passing a _greeting argument that will passed in during deployment to initialize the state variable greeting.
function getGreeting() public view returns (string memory){
return greeting;
}
function setGreet(string memory _greeting) public {
// string memory greet = _greeting;
greeting = _greeting;
}
Here we are creating two functions, the first function has a returns added to it to show that it actually returns a value. In this case greeting.
The second function is just a fancy function that takes in a string argument and sets that argument to the state variable.
Compiling your smart contract
Thanks to the remix Ethereum IDE, we can be able to compile our solidity code in the browser.
- Locate the compile icon on the side bar to your left and click on it.
- Ensure that your version tallies with the you used on your smart contract.
- Set language to "Solidity" (You can still use Liquidity language... Kidding yo)
- EVM version - Compiler Default.
- You can also leave it at auto compile.
- Then hit the *compile * button.
Great! You just wrote and compiled your first solidity smart contract. (It's time you build your own Binance clone yo. You're good. Allow we mortals to continue playing around with good old "padding-left: 2px")
Its time to deploy!!
Oi! Oi!! Hold up tiger... We will be using injected web 3 so go get your Metamask account.
Installing Metamask
Meta mask extension can be installed using the google chrome store here.
Install it, create an account, get your seed phrase, and then toggle on the show other networks option.
Yoo... We are making progress here.
How to get some Ethereum for the Rinkeby test network
To get some eth, first switch your account from Ethereum Main Network to Rinkeby network.
- Once you do that hit the button with the weird zeros to copy your Rinkeby contract address.
Stop by this website https://rinkebyfaucet.com/
- Paste your wierd zeros in there and hit the Send Me Eth button, (Yoo, you got to beg them to send you some eth, so be humble)
It usually takes a couple of seconds to get your 0.1 Eth
(We rich yo. Time to start pricing land in your village.)
Deploying to Rinkeby test network using Injected Web 3
Next, go back to your Remix Ethereum IDE and hit the deploy icon by your left, just beneath the compile icon on the side bar. you should see the below screen.
- Now switch that from Javascript VM to Injected Web 3.
Leave the gas limit and every other thing as is and then type in a greeting on the provided text field ( Remember the constructor thingy? Damn, I knew you forgot! I need an Uzi somebody.)
Enter some greeting and hit the deploy button.
PS: Enter the text in quotes, "Oi!" like so.
A screen is going to appear and ask you to connect Metamask. Do that real quick.
The next screen is going to be a gas fee charge, just hit on approve and boom!!! You successfully deployed your smart contract to Rinkeby. (Drinks on me!)
You can view the transaction on EtherScan or whatever you want to do with it.
My name is Sparkle and I am signing out yo. Follow me for more of these step by step articles.
Top comments (0)