Table of Contents
Remix IDE is an open-source web and desktop application. It is a powerful open-source tool that helps you write Solidity contracts straight from the browser.
Remix-IDE is available at remix.ethereum.org. The project is available at GitHub Repository and the docs are available at this link.
When you first visit Remix IDE you will see this window.
There will be three default folders in remix namely contracts
, scripts
, and tests
.
There will be three smart contracts( .sol files ) inside the contracts folder and two scripts( .js files ) inside the scripts folder and one test( .sol file ) inside the test folder.
Explore: How to write a smart contract and NFT on OpenSea
Creating a new Smart Contract in Remix
Create a new MyContract.sol
file inside the contracts folder. You can create a new file by clicking the file button at the top of the folders.
Creating smart contract logic
We will create a simple smart contract that will store and update a variable in the blockchain.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract MyContract {
// state variable num
uint256 public num;
// function sets value of variable num equal to _num
function setNum(uint256 _num) public returns(uint256) {
num = _num;
return num;
}
}
You can view the gist here.
Compiling and deploying the contract
To compile the contract click on the solidity icon on the left menu.
Now click on Compile MyContract.sol
to compile the contract. If the contract compiles perfectly, you will see a green tick with the solidity icon(as shown in the image above).
Bookmark for later: How does Ethereum work?
To deploy the contract click on the Ethereum icon on the left menu and then click on the Deploy
button.
After deploying the contract you will see your contract under the deployed contracts (as shown in the image above).
Now we can test the smart contract by updating the num
variable.
Updating the variable
We can update the num
variable, using the setNum
function by entering an integer value as shown below and then clicking on setNum
(in orange color). This will store the integer value, that we enter inside the num variable.
Now you can check the value of the variable by clicking on num
(in blue color). The value stored inside num will be displayed below it(as shown in the image above).
Congratulations! You have built and tested a smart contract on Remix IDE.
If you need to try out something more challenging, enroll in this course 🤙🏼 Launch your own epic NFT marketplace