1

I want to write a Smart contract where for a call to a specific function, for example, erc20Pay, not ETH will be accepted, but a regular erc20 token with a specific contract address. how can this be implemented on solidity

1 Answer 1

0

Smart Contracts depend on the specific ideals of the governance from burn to non burn tokens to DAO governance.

  function transferFrom(address sender, address recipient, uint256 amount) 
external returns (bool);
function balanceOf(address account) external view returns (uint256);


constructor(address _tokenAddress, uint _price) {
    tokenAddress = _tokenAddress;
    price = _price;
}

function buy() public {
    IERC20 token = IERC20(tokenAddress);
    uint tokensNeeded = price * 1 ether;
    require(token.balanceOf(msg.sender) >= tokensNeeded, "Insufficient funds");
    require(token.transferFrom(msg.sender, address(this), tokensNeeded), "Token 
  transfer failed");
    // execute function
}
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.