Creating and deploying your first smart contract using Remix Ethereum IDE
We'll cover the basics of Solidity programming language, including data types, functions, modifiers, events, and error handling.
Add code examples, explanations, or diagrams about Solidity basics here.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleToken {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply * 10**uint256(_decimals);
balanceOf[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
function transfer(address _to, uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value, "Insufficient balance");
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value, "Insufficient balance");
require(allowance[_from][msg.sender] >= _value, "Insufficient allowance");
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
allowance[_from][msg.sender] -= _value;
emit Transfer(_from, _to, _value);
return true;
}
}
Using Remix IDE, create a contract that can store and retrieve a string value. Include functions to set and get the value.
Hint: Use a public state variable and create setter/getter functions.
Modify the sample ERC-20 token contract to add a function that allows the owner to mint new tokens.
Hint: Add an owner variable and a modifier to restrict access to certain functions.
Deploy your token contract to the Remix VM environment and test all its functions. Document any issues you encounter.
Hint: Use different accounts in Remix to test transfer functionality between users.