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 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
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 at MyContract.sol.
For learning more about solidity visit Solidity by Example
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).
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.
Hope you enjoyed the article! If you have any questions or comments, feel free to drop them below or reach out to me on Twitter!
Top comments (1)
How do you use remix Solidity IDE? spell to make him stop cheating