// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract RoboVanToken {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address => uint256) private balancesToken;
mapping(address => mapping(address => uint256)) private allowancesToken;
// ERC20 Events
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed tokenOwner,
address indexed spender,
uint256 value
);
constructor() {
name = "ROBOVAN";
symbol = "ROBOVAN";
decimals = 18;
totalSupply = 2123456789 * 10 ** 18;
balancesToken[msg.sender] = totalSupply;
emit Transfer(address(0), msg.sender, totalSupply);
}
// Function to transfer tokens
function transfer(
address recipient,
uint256 amount
) external returns (bool) {
require(balancesToken[msg.sender] >= amount, "can't transfer");
require(recipient != address(0), "0x0");
balancesToken[msg.sender] -= amount;
balancesToken[recipient] += amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}
// Function to approve spending on behalf of the owner
function approve(address spender, uint256 amount) external returns (bool) {
require(spender != address(0), "0x0");
allowancesToken[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
// Function to transfer tokens using allowance
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool) {
require(sender != address(0), "0x0");
require(recipient != address(0), "0x0");
require(balancesToken[sender] >= amount, "can't transfer");
require(allowancesToken[sender][msg.sender] >= amount, "exceeded");
balancesToken[sender] -= amount;
balancesToken[recipient] += amount;
allowancesToken[sender][msg.sender] -= amount;
emit Transfer(sender, recipient, amount);
return true;
}
// View function to get balance of an account
function balanceOf(address addr) external view returns (uint256) {
return balancesToken[addr];
}
// View function to get allowance between owner and spender
function allowance(
address addr,
address user
) external view returns (uint256) {
return allowancesToken[addr][user];
}
}
{
"compilationTarget": {
"contracts/newToken/Token.sol": "RoboVanToken"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 300
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenOwner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]