Max Wallet: Mecanismo antiballena para tu 토큰
11750 단어 blockchainweb3defisolidity
Antes de iniciar
Segurate de instalar Metamask y agregar fondos de Rinkeby Testnet que puedes conseguir desde el Faucet . También necesitarás conectar tu wallet a Polygon Mainnet y conseguir MATIC desde algún exchange.
Max wallet fijo(Advertencia: ¡No lanzar este 토큰!)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20
{
uint public maxWalletAmount;
address CREATOR;
constructor () ERC20("My Token", "TKN")
{
CREATOR = msg.sender;
_mint(msg.sender, 1000000 ether);
maxWalletAmount = 1000 ether;
}
function _beforeTokenTransfer(
address from,
address to,
uint amount
) internal virtual override(ERC20)
{
require(to == CREATOR || balanceOf(to) + amount <= maxWalletAmount, "Max Wallet Limit Exceeds!");
super._beforeTokenTransfer(from, to, amount);
}
}
최대 지갑 avanzado
메조라스:
네트워크에 의존하는 라우터 방향 조정:
0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff
0x10ED43C718714eb63d5aA57B78B54704E256024E
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
0xD99D1c33F9fC3444f8101754aBC46c52416550D1
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
}
contract MyToken is ERC20, Ownable
{
uint public maxWalletAmount;
mapping(address => bool) public isMaxTxExempt;
address public pair;
constructor () ERC20("My Token", "TKN")
{
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);
pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
isMaxTxExempt[msg.sender] = true;
isMaxTxExempt[pair] = true;
_mint(msg.sender, 1000000 ether);
setMaxWalletPercentage(100);
}
function _beforeTokenTransfer(
address from,
address to,
uint amount
) internal virtual override(ERC20)
{
require(isMaxTxExempt[to] || balanceOf(to) + amount <= maxWalletAmount, "Max Wallet Limit Exceeds!");
super._beforeTokenTransfer(from, to, amount);
}
function setMaxWalletPercentage(uint256 percentage) public onlyOwner {
maxWalletAmount = (totalSupply() * percentage) / 10000;
}
function setMaxTxExempt(address account, bool value) external onlyOwner {
isMaxTxExempt[account] = value;
}
}
¡ Gracias por ver este 튜토리얼!
Sígueme en dev.to y en para todo lo relacionado al desarrollo en Blockchain en Español.
Reference
이 문제에 관하여(Max Wallet: Mecanismo antiballena para tu 토큰), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/turupawn/max-wallet-mecanismo-antiballena-para-tu-token-1hn8텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)