Skip to content

Multiple contracts, with a contract that is not created #184

@jaa2

Description

@jaa2

Is it possible to define variables representing addresses contracts with known interfaces which aren't created by the contract referring to them?

For example, could you write an act specification for this?

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

interface IERC20 {
    function transfer(address recipient, uint256 amount) external;
}

contract TransferOneToken {
    IERC20 public token;

    constructor(IERC20 _tokenAddress) {
        require(address(_tokenAddress) != address(0), "Invalid token address");
        token = _tokenAddress;
    }

    function transfer() public {
        // Transfer 1 token from the contract to the sender
        uint256 transferAmt = 1;
        token.transfer(msg.sender, transferAmt);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions