라타끄 뒤 샌드위치
Eneigenphi des exemples des Attaques de Sandwich on chain.
전위 드 초보자
Pour ce video tu auras besoin de Metamask ou n'importe quel wallet compatible avec l'EVM et aussi du GoerliETH que tu peux trouver gratuitement en un faucet .
토큰 ERC20 avec mécanisme 안티 샌드위치
Faites는 블록체인 que vous êtes en train d'utiliser에 라우터가 존재하지 않는 유틸리티에 주목합니다.
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff
0x10ED43C718714eb63d5aA57B78B54704E256024E
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router {
function factory() external pure returns (address);
function WETH() external pure returns (address);
}
contract MyToken is ERC20 {
mapping(address => uint256) public lastTxByAddress;
uint public blockCooldownAmount = 1;
address pair;
constructor() ERC20("My Token", "MTKN") {
_mint(msg.sender, 1_000_000 ether);
IUniswapV2Router uniswapRouter = IUniswapV2Router(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
pair = IUniswapV2Factory(uniswapRouter.factory()).createPair(address(this), uniswapRouter.WETH());
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
amount;
if(from == pair)
{
ensureMaxTxFrequency(to);
lastTxByAddress[to] = block.number;
} else if(to == pair)
{
ensureMaxTxFrequency(from);
lastTxByAddress[from] = block.number;
}else
{
ensureMaxTxFrequency(from);
lastTxByAddress[from] = block.number;
ensureMaxTxFrequency(to);
lastTxByAddress[to] = block.number;
}
}
function ensureMaxTxFrequency(address addr) internal virtual {
bool isAllowed = lastTxByAddress[addr] == 0 ||
((lastTxByAddress[addr] + blockCooldownAmount) < (block.number + 1));
require(isAllowed, "Max tx frequency exceeded!");
}
}
¡ Merci pour voir ce 비디오!
Suivez nous ici en dev.to et en pour ce qui a à voir avec Blockchain en Francais.
Reference
이 문제에 관하여(라타끄 뒤 샌드위치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/filosofiacodigofra/lattaque-du-sandwich-i6g텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)