startToken.sol
plain_text2 years ago
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
contract StarToken {
// Public variables for token details
string public tokenName;
string public tokenAbbrv;
uint public totalSupply;
// Mapping to store balances
mapping(address => uint) public balances;
// Events to emit on minting and burning tokens
event Mint(address indexed to, uint256 amount);
event Burn(address indexed from, uint256 amount);
// Constructor to initialize the token details
constructor() {
tokenName = "StarCoin";
tokenAbbrv = "STAR";
totalSupply = 0;
}
// Function to mint new tokens
function mint(address _to, uint _amount) public {
require(_to != address(0), "Mint to the zero address is not allowed");
totalSupply += _amount;
balances[_to] += _amount;
emit Mint(_to, _amount);
}
// Function to burn existing tokens
function burn(address _from, uint _amount) public {
require(_from != address(0), "Burn from the zero address is not allowed");
require(balances[_from] >= _amount, "Insufficient balance to burn");
balances[_from] -= _amount;
totalSupply -= _amount;
emit Burn(_from, _amount);
}
// Function to get the balance of an account
function balanceOf(address _account) public view returns (uint) {
return balances[_account];
}
}CryptoToken.sol
plain_text2 years ago
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
contract CryptoToken {
// Public variables
string public tokenName;
string public tokenAbbrv;
uint public totalSupply;
// Balances mapping
mapping(address => uint) public balances;
// Events for minting and burning tokens
event Mint(address indexed to, uint256 value);
event Burn(address indexed from, uint256 value);
// Constructor to initialize token details
constructor() {
tokenName = "CryptoCoin";
tokenAbbrv = "CC";
totalSupply = 0;
}
// Function to mint tokens
function mint(address _to, uint _value) public {
require(_to != address(0), "Invalid address");
totalSupply += _value;
balances[_to] += _value;
emit Mint(_to, _value);
}
// Function to burn tokens
function burn(address _from, uint _value) public {
require(_from != address(0), "Invalid address");
require(balances[_from] >= _value, "Not enough tokens to burn");
balances[_from] -= _value;
totalSupply -= _value;
emit Burn(_from, _value);
}
// Function to check the balance of an address
function balanceOf(address _account) public view returns (uint) {
return balances[_account];
}
}CustomToken.sol
plain_text2 years ago
contract CustomToken {
// public variables here
string public tokenName = "CUSTO";
string public tokenAbbrv = "CTO";
uint public totalToken = 0 ;
// mapping variable here
mapping (address => uint) public wallets;
// mint function
function mint ( address _address, uint _val) public {
totalToken += _val;
wallets[_address] += _val;
}
// burn function
function burn ( address _address, uint _val) public {
if(wallets[_address] >= _val){
totalToken -= _val;
wallets[_address] -= _val;
}else revert("User don't have enough token to burn");
}
}second code for eth
plain_text2 years ago
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyToken {
// Public variables for token details
string public name = "PiToken";
string public symbol = "PTK";
uint256 public totalSupply;
// Mapping of addresses to balances
mapping(address => uint256) public balances;
// Event to log the minting of tokens
event Mint(address indexed to, uint256 amount);
// Event to log the burning of tokens
event Burn(address indexed from, uint256 amount);
// Mint function to create new tokens
function mint(address _to, uint256 _value) public {
require(_to != address(0), "Invalid address");
totalSupply += _value;
balances[_to] += _value;
emit Mint(_to, _value);
}
// Burn function to destroy tokens
function burn(address _from, uint256 _value) public {
require(_from != address(0), "Invalid address");
require(balances[_from] >= _value, "Insufficient balance");
totalSupply -= _value;
balances[_from] -= _value;
emit Burn(_from, _value);
}
}
Solidity Smart Contract
plain_text2 years ago
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
/*
REQUIREMENTS
1. Your contract will have public variables that store the details about your coin (Token Name, Token Abbrv., Total Supply)
2. Your contract will have a mapping of addresses to balances (address => uint)
3. You will have a mint function that takes two parameters: an address and a value.
The function then increases the total supply by that number and increases the balance
of the “sender” address by that amount
4. Your contract will have a burn function, which works the opposite of the mint function, as it will destroy tokens.
It will take an address and value just like the mint functions. It will then deduct the value from the total supply
and from the balance of the “sender”.
5. Lastly, your burn function should have conditionals to make sure the balance of "sender" is greater than or equal
to the amount that is supposed to be burned.
*/
contract MyToken {
// public variables here
string public tokenName = "matic";
string public tokenAbbrv = "mtc";
uint public totalToken = 0 ;
// mapping variable here
mapping (address => uint) public wallets;
// mint function
function mint ( address _address, uint _val) public {
totalToken += _val;
wallets[_address] += _val;
}
// burn function
function burn ( address _address, uint _val) public {
if(wallets[_address] >= _val){
totalToken -= _val;
wallets[_address] -= _val;
}else revert("Not enough token to burn");
}
}