Contract Source Code:
File 1 of 1 : SOL
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SOL {
string public name = "Solana"; // Token Name
string public symbol = "SOL"; // Token Symbol
uint8 public decimals = 18; // Number of decimals (18 is standard for ERC20)
uint256 public totalSupply; // Total supply of the token
mapping(address => uint256) public balanceOf; // Mapping to store the balance of each address
mapping(address => mapping(address => uint256)) public allowance; // Mapping for allowance (spending on behalf of others)
// Events (optional but standard)
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
// Constructor to initialize total supply and assign it to the deployer's address
constructor(uint256 initialSupply) {
totalSupply = initialSupply * 10 ** uint256(decimals); // Adjust for decimals
balanceOf[msg.sender] = totalSupply; // Assign total supply to deployer's address
emit Transfer(address(0), msg.sender, totalSupply); // Emit the Transfer event
}
// Transfer tokens from the sender to the recipient
function transfer(address recipient, uint256 amount) public returns (bool) {
require(recipient != address(0), "ERC20: transfer to the zero address");
require(balanceOf[msg.sender] >= amount, "ERC20: insufficient balance");
balanceOf[msg.sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}
// Allow an address to spend a specified amount of tokens on behalf of the sender
function approve(address spender, uint256 amount) public returns (bool) {
require(spender != address(0), "ERC20: approve to the zero address");
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
// Transfer tokens from one address to another, based on allowance
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(balanceOf[sender] >= amount, "ERC20: insufficient balance");
require(allowance[sender][msg.sender] >= amount, "ERC20: allowance exceeded");
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
allowance[sender][msg.sender] -= amount;
emit Transfer(sender, recipient, amount);
return true;
}
// Get the remaining number of tokens a spender is allowed to transfer on behalf of an owner
function getAllowance(address owner, address spender) public view returns (uint256) {
return allowance[owner][spender];
}
// Mint new tokens (can only be called by the contract owner or a specified minter)
function mint(address account, uint256 amount) public returns (bool) {
require(account != address(0), "ERC20: mint to the zero address");
totalSupply += amount;
balanceOf[account] += amount;
emit Transfer(address(0), account, amount);
return true;
}
// Burn tokens (destroy tokens from the caller's balance)
function burn(uint256 amount) public returns (bool) {
require(balanceOf[msg.sender] >= amount, "ERC20: burn amount exceeds balance");
totalSupply -= amount;
balanceOf[msg.sender] -= amount;
emit Transfer(msg.sender, address(0), amount);
return true;
}
}