Smart Marketplace Contract:

  1. allow user to list the erc20 tokens to sell at what price in matic

  2. the buyers need to provide permission to the contract to interact with the smart contract

  3. the seller can cancel the listing at anytime

ropsten network: https://ropsten.etherscan.io/address/0x2b63337c28cda55faeefde136636f8eb854ef5ba Then, I try interact with the contact but get errors when executing the contract in the text fields of: priceNumerator; priceDenominator;

pragma solidity ^0.8.4;


import "@openzeppelin/contracts/token/ERC20/ERC20.sol";


contract TokenMarket {
    struct Listing {
        address seller;
        ERC20 token;
        uint256 unitsAvailable;

        // wei/unit price as a rational number
        uint256 priceNumerator;
        uint256 priceDenominator;
    }

    Listing[] public listings;

    event ListingChanged(address indexed seller, uint256 indexed index);

    function list(
        ERC20 token,
        uint256 units,
        uint256 numerator,
        uint256 denominator
    ) public {
        Listing memory listing = Listing({
            seller: msg.sender,
            token: token,
            unitsAvailable: units,
            priceNumerator: numerator,
            priceDenominator: denominator
        });

        listings.push(listing);
        emit ListingChanged(msg.sender, listings.length-1);
    }

    function cancel(uint256 index) public {
        require(listings[index].seller == msg.sender);
        delete(listings[index]);
        emit ListingChanged(msg.sender, index);
    }

    function buy(uint256 index, uint256 units) public payable {
        Listing storage listing = listings[index];

        require(listing.unitsAvailable >= units);
        listing.unitsAvailable -= units;
        require(listing.token.transferFrom(listing.seller, msg.sender, units));

        uint256 cost = (units * listing.priceNumerator);
            listing.priceDenominator;
        require(msg.value == cost);
            //listing.seller.transfer(cost);

        emit ListingChanged(listing.seller, index);
    }
}
0

There are 0 answers