Smart contract code for Anyone can send coins to each other without a need for registering with a username and password with help of Ethereum keypair

Smart contract code for Anyone can send coins to each other without a need for registering with a username and password with help of Ethereum keypair


The contract allows only its creator to create new coins (different issuance schemes are possible). Anyone can send coins to each other without a need for registering with a username and password, all you need is an Ethereum keypair.


 // SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.4;


contract Coin {

    // The keyword "public" makes variables

    // accessible from other contracts

    address public minter;

    mapping (address => uint) public balances;


    // Events allow clients to react to specific

    // contract changes you declare

    event Sent(address from, address to, uint amount);


    // Constructor code is only run when the contract

    // is created

    constructor() {

        minter = msg.sender;

    }


    // Sends an amount of newly created coins to an address

    // Can only be called by the contract creator

    function mint(address receiver, uint amount) public {

        require(msg.sender == minter);

        balances[receiver] += amount;

    }


    // Errors allow you to provide information about

    // why an operation failed. They are returned

    // to the caller of the function.

    error InsufficientBalance(uint requested, uint available);


    // Sends an amount of existing coins

    // from any caller to an address

    function send(address receiver, uint amount) public {

        if (amount > balances[msg.sender])

            revert InsufficientBalance({

                requested: amount,

                available: balances[msg.sender]

            });


        balances[msg.sender] -= amount;

        balances[receiver] += amount;

        emit Sent(msg.sender, receiver, amount);

    }

}

Comments

Last 7 Days

How to use autoplay and mute attribute with < video > tag in HTML for youtube ? with example

How to use referrerpolicy Attribute value (strict-origin ) with < iframe > tag in HTML ? with example

How to use the datalist tag in HTML?

Why TD is used in HTML?

How to use string in Solidity programming language ?

How to add Amazon website inside iframe?