How to Develop Smart Contract on Remix IDE?
Follow the steps below to develop a smart contract on Remix IDE:
Step 1: Open the Remix IDE and click on the File Explorer.
Step 2: Select create a new workspace option from the drop-down menu.
Step 3: Enter the name of the new workspace w3wiki.
Step 4: In the workspace w3wiki, right-click on the option contracts and select the option New File.
Step 5: Create a new file Bank.sol.
Step 6: Paste the below code in Bank.sol.
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Bank
{
address Owner;
// Creating the Mapping for the Adding &
// Transfer Amount in Account
mapping(address=>uint)Balance;
// Constructor for the address of the Owner
constructor()
{
Owner = msg.sender;
}
// Function for adding the Ethereum in Account
function depositBalance(uint amount) public returns(uint)
{
// First check whether it is Owner's Account or Not
require(msg.sender == Owner, "This is Owner's Account !!");
Balance[msg.sender] = Balance[msg.sender] + amount;
return Balance[msg.sender];
}
// Function to Get the Balance from an Account
function displayBalance() public view returns(uint)
{
return Balance[msg.sender];
}
// Function to transfer the Amount from Owner to Recipient
function Transfer(address recipient, uint amount) public
{
// Function to check the Self account is or not
require(msg.sender != recipient, "Can't Transfer !! Self Account.");
// Function to check the owner has balance is available or not
require(Balance[msg.sender] >= amount, "Insufficient Balance !!");
_transfer(msg.sender, recipient, amount);
}
function _transfer(address From, address To, uint Amount) private
{
Balance[From] = Balance[From] - Amount;
Balance[To] = Balance[To] + Amount;
}
}
Explanation:
There are 4 functions in the smart contract Bank.sol:
- depositBalance()
- require(msg.sender == Owner, “This is Owner’s Account !!”) : Address is checked to determine if it is owner’s address or not.
- Balance[msg.sender] = Balance[msg.sender] + amount : Amount is added to the available balance in the account.
- transfer()
- require(msg.sender != recipient, “Can’t Transfer !! Self Account.”) : This checks recipient address against sender’s address, if the address is matching a message is displayed “Can’t Transfer !! Self Account”.
- require(Balance[msg.sender] >= amount, “Insufficient Balance !!”) : This checks whether the requested amount is less than the available balance or not. If not, then a message is displayed “Insufficient Balance”.
- _transfer(msg.sender, recipient, amount): If recipient address is correct and balance is available then _transfer() function is invoked.
- _transfer()
- Balance[From] = Balance[From] – Amount: Balance is deducted from sender’s account.
- Balance[To] = Balance[To] + Amount: Balance is added to recipient’s account.
- displayBalance()
- return Balance[msg.sender]: This will display sender’s account balance.
Steps to Create, Test and Deploy Ethereum Smart Contract
Smart contracts are self-execution programs stored on a blockchain that are automatically executed when predefined conditions are met. They allow the participants on the blockchain to transact with each other without a trusted central authority. After creating a smart contract, the next step is to deploy the smart contract onto a blockchain for execution. For this purpose, developers often use development tools such as Remix IDE. This article focuses on discussing steps to create, test, and deploy the Ethereum Smart Contract on Remix Tool.
Table of Content
- What is Remix IDE?
- Getting Started With Remix IDE
- What is Solidity Programming Language?
- How to Develop Smart Contract on Remix IDE?
- Steps to Compile the Smart Contract
- Steps to Deploy the Smart Contract
- Conclusion
- Frequently Asked Questions related to Steps to Create, Test and Deploy Ethereum Smart Contract
Contact Us