我是刚开始踏实的,我发现这个简短而又甜蜜的智能契约可以用来创建你自己的令牌,而且效果很好。
我真正想要做的是在这个极其简单的简短代码中添加反射,这样我就可以确切地了解它是如何工作的。
这是我的代码,摘自此链接
// 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;
}
}您能修改此代码以添加反射吗?对于新的令牌开发人员来说,缺乏简单的资源,对我来说理解反射是非常有帮助的。
任何在混炼上运行的工作代码的答案都将是非常棒和有帮助的,我相信对于智能契约创建者来说,这将是一个很好的资源。
发布于 2023-02-18 04:47:00
发布于 2023-02-21 09:26:57
当您使用标准ERC20令牌代码很容易的时候,您可以轻松地创建一个反射令牌。在这种情况下,你也应该知道一些简单的经济因素,比如通货紧缩和通货膨胀是如何运作的。你可以使用github的反射合同。反射令牌示例
看看合同中的主要函数,如_getCurrentSupply和_getRate,这两种方法给出了令牌处于通缩或拐点状态的条件。当供给减少时,利率会增加,因此在所有令牌持有者中都会自动发生反射。每个交易者都收取一定的费用,交易越多,就会收取更多的费用,从而产生更多的通货紧缩,意味着更多的稀缺。你可以深入了解这一切是如何运作的。
https://ethereum.stackexchange.com/questions/144797
复制相似问题