Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Introduction

This is a basic code written in Solidity, a programming language used to create smart contracts for the Ethereum network. The program is a simple contract consisting of two functions and several variables. The variables include two strings, one unsigned integer (uint), and a mapping variable. The mapping variable maps addresses to unsigned integers.

As for the functions, the first one is called "mint" and it increases the balances. The second function is called "burn" and it is the opposite of the "mint" function. The "burn" function also

Project Code Explanation

The contract begins with a special comment, // SPDX-License-Identifier: MIT, which specifies the MIT license under which the code is distributed. This indicates that the code can be used, modified, and distributed under the terms of the MIT license. The next line of code, pragma solidity 0.8.18;, specifies the version of the Solidity programming language used in the contract. In this case, the contract is written using Solidity version 0.8.18.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

The contract itself is named Tokening. It will serve as the main implementation for the token functionality. The contract defines several public variables to store information about the token. These variables include tokenName, which represents the name of the token, tokenSymbol, which represents the symbol or abbreviation of the token, and totalSupply, which keeps track of the total supply of the token.

contract Tokening {

    string public tokenName="Divesh";
    string public tokenSymbol="B.tech";
    uint256 public totalSupply=0;

A mapping named balances is declared within the contract. This mapping associates addresses with their corresponding token balances. It will be used to keep track of the token balances for each address

mapping(address => uint256) public balances;

The mint function is an external function that can be called to create new tokens and assign them to a specified address. It takes two parameters: _to, representing the address to receive the tokens, and _value, representing the amount of tokens to be minted. Inside the function, the totalSupply is increased by _value, and the token balance of the _to address is incremented accordingly.

    function mint(address _to, uint256 _value) external {
        totalSupply += _value;
        balances[_to] += _value;
    }

The burn function is an external function that allows the caller to burn or destroy tokens from their own balance. It takes one parameter: _value, representing the amount of tokens to be burned. The function first checks that the caller's balance is sufficient for the burn operation using a require statement. If the check passes, the totalSupply is decreased by _value, and the token balance of the caller's address is decreased accordingly. However Both the mint and burn functions include require statements to validate certain conditions. In the mint function, it ensures that the _to address is not an invalid address (address(0)). In the burn function, it checks that the caller's balance is greater than or equal to the amount of tokens to be burned. These require statements act as a guard to prevent invalid operations and ensure the contract's intended behavior

    function burn(uint256 _value) external {
        require(balances[msg.sender] >= _value, "Low balance");
        totalSupply -= _value;
        balances[msg.sender] -= _value;
    }

About

Ethereum smart contract project built with Solidity — token management, access control, and gas-optimized contract design.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages