Approve

Standards

Définition

Fonction standard ERC-20 qui autorise un contrat (ou une adresse) à dépenser vos tokens à votre place. Nécessaire avant tout swap, staking ou interaction DeFi. Créé une allowance que le contrat peut utiliser avec transferFrom(). Attention : approuver une somme illimitée expose à des risques si le contrat est malveillant.

Version anglaise

Standard ERC-20 function that authorizes a contract (or address) to spend your tokens on your behalf. Required before any swap, staking or DeFi interaction. Creates an allowance the contract can use with transferFrom(). Warning: unlimited approvals expose you to risks if the contract is malicious.

Exemple de Code

// Interface ERC-20
function approve(address spender, uint256 amount) external returns (bool);

// Utilisation classique
USDC.approve(address(uniswapRouter), type(uint256).max); // ⚠️ Approbation illimitée
// Mieux (approbation exacte) :
USDC.approve(address(uniswapRouter), 1000e6); // Exactement 1000 USDC

Termes Liés

Pratique ce concept sur Solingo

Maîtrise Approve avec des exercices interactifs et un IDE intégré.

Commencer gratuitement