SOCI4L

Letting someone spend for you

Step 1 of 4
0 of 2 goals

Write down the permission

allowance is a mapping of a mapping: owner, then spender, then how much.

Fill in approve:

allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);

Nothing moves. You are recording a permission, and the token has not left your balance.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Token {
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor() {
        totalSupply = 1000;
        balanceOf[msg.sender] = totalSupply;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        return true;
    }
}

Goals

The contract compiles
nothing to compile yet
Emit `Approval`
the contract has not run yet

Contract storage

Write a contract and it will deploy itself here.