2

I'm new to solidity, and I found this short and sweet smart contract for creating you own token, and it works really well.

What I would really like to do is add reflections to this exceedingly simple short code, so I can learn exactly how it works.

Here is my code, taken from this link

// Code from:
// https://medium.com/huawei-developers/create-your-own-bep20-token-in-10-minutes-1118c4e82454

// Go here to code:
// https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.7+commit.e28d00a7.js

// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.4;
// contract address: 
// symbol: ATT
/**
 * @title Adams_contract
 * @dev Very simple BEP20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `BEP20` functions.
 * USE IT ONLY FOR LEARNING PURPOSES. SHOULD BE MODIFIED FOR PRODUCTION
 */
 
contract Adams_Token {
    string public name = "Adams Test Token 2";
    string public symbol = "ATT";
    uint256 public totalSupply = 999999999999999999000000000000000000; // many tokens
    uint8 public decimals = 18;
    
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed _from, address indexed _to, uint256 _value);

     /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor() {
        balanceOf[msg.sender] = totalSupply;
    }

     /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address _to, uint256 _value)
        public
        returns (bool success)
    {
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
    
     /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */

    function approve(address _spender, uint256 _value)
        public
        returns (bool success)
    {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address _from,
        address _to,
        uint256 _value
    ) public returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}

Can you amend this code to add reflections? There is a lack of simple resources out there for new token developers and it would be really helpful for me to understand reflections.

Any answer with working code that runs on remix would be really wonderful and helpful and I'm sure it would be a great resource for smart contract creators.

4
  • What do you exactly mean by reflections. To explain the code line by line? Commented Feb 16, 2023 at 17:01
  • @infamousdegen not exactly, reflections are basically a tax on coin movements paid to holders automatically by the network. No explaining needed, but thank you.
    – Adjam
    Commented Feb 17, 2023 at 20:14
  • @Adjam, is this contract holding the eth /coins to distribute, when you mean coin movements/ do you mean nft movements?
    – donoso.eth
    Commented Feb 19, 2023 at 8:21
  • @donoso.eth I'm not sure if it works for NFTs, its for coins as far as I know
    – Adjam
    Commented Feb 19, 2023 at 19:01

2 Answers 2

4
+50

If you are new to solidity and looking to develop tokens, you should definitely look at ERC20 standards. It is the most adopted and accepted standard for fungible tokens by the community. To understand how ERC20 tokens work, you can read Ethereum docs.

In your case, I think you can find your answer via this link. Where it deploys a simple ERC20 contract with market fees on each transaction.

Hope it helped!

1
  • 1
    Thank you for this answer :)
    – Adjam
    Commented Feb 19, 2023 at 20:03
3

You can easily create a reflection token when you are easy with standard ERC20 token code. You should also know simple ecomincs in this conditon like how deflation and inflation work. You can work with this reflect-contract from github. Reflection Token Example

Look at the main functions in the contract like _getCurrentSupply and _getRate these 2 methods are giving you at what condition the token is in either in deflation or in inflection. When supply decrease the rate increase and hence the reflection occur automatically in all token holders. Certain fee is taken from every trader, more the trading happen more fee will be collected and hence more deflation occur meaning more scarcity. You can dive deep to know how all this work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.