How to implement clock auction from smart contract in javascript

Hi Community,

I cloned rariable with Moralis tutorial but I am stuck with this problem.I wanna add auction for dapp but I could not figure out how to do it. I watched also another tutorial from Moralis about auction , I tried that with ether remix that works perfectly but could not implement for my dapp.I am also in Ivan academy and still learning about programming.Thank you so much.

My GitHub link

this is my auction.

pragma solidity >=0.7.0 <0.9.0;

contract SimpleAuction{
    address payable public beneficiary;
    uint public auctionEndTime;
    address public highestBidder;
    uint public highestBid;
    mapping(address => uint) public pendingReturns;
    bool ended = false;
    event HighestBidIncrease(address bidder, uint amount);
    event AuctionEnded(address winner, uint amount);
    constructor(uint _biddingTime, address payable _beneficiary){
        beneficiary = _beneficiary;
        auctionEndTime = block.timestamp + _biddingTime;
    function bid() public payable{
        if (block.timestamp > auctionEndTime){
            revert("The auction has already ended");
        if (msg.value <= highestBid){
            revert("There is alreay a higher or equal bid");
        if (highestBid != 0){
            pendingReturns[highestBidder] += highestBid;
        highestBidder = msg.sender;
        highestBid = msg.value;
        emit HighestBidIncrease(msg.sender, msg.value);
    function withdraw() public returns (bool){
        uint amount = pendingReturns[msg.sender];
        if(amount > 0){
            pendingReturns[msg.sender] = 0;
                pendingReturns[msg.sender] = amount;
                return false;
        return true;
    function auctionEnd() public{
        if (block.timestamp < auctionEndTime){
            revert ("The auction has not ended yet");
        if (ended){
            revert("the function auctionEnded has already been called");
        ended = true;
        emit AuctionEnded(highestBidder, highestBid);
1 Like

Hey @aliekber1976

I cant understand … what is the problem? Smart contract or frontend is not working correctly?

Thank you :sweat_smile:

If the problem is on the front end side, take a look at

Left code - from the tutorial,
Right - your

1 Like

I can’t find the smart contract from your question on your repo

Thank for quick reply :slight_smile: my problem is , I wanna create auction function for my dapp actually for NFT market but I don’t know how I do that in javascript. I want the users can make offer for their NFT. it wasn’t in tutorial , I wanna do that extra maybe It can be also sample for other Moralis students. I tried some codes from GitHub but did not work exactly. my repo doesn’t include yet contract for auction because I was just trying that by myself.

as much as I understood , I need to put auction contract in my marketplace contract and I need to create 3 buttons , make a offer , withdraw and cancel auction and time input then chance abi file and write logic in javascript :slight_smile: , I have problem with javascript part :slight_smile:

You need to modificate smart contract from the Rarible Clone tutorial. It doesn’t have “accept offers” function. Then on the front end part you need to upgrade your code(and update ABI). As you said, you need to add more buttons. These buttons will be needed for calling methods from the smart contract.


          web3.utils.toWei(createItemPriceField.value, "ether")
        .send({ from: userAddress });

Unfortunately, we cannot write a smart contract for you. But feel free to ask any questions.

Just #BUIDL it :man_mechanic:

Thank you for fast responding , no definitely not , I try to build that by myself.those answers helped me actually how I can start it and I will take a smart contract course 202 on Ivan tech , I think it might be really helpful for me. I will definetly have more questions in future :slight_smile: have a great weekend.

1 Like


I will wait for the release :man_mechanic:

Good luck, keep up the good work! :muscle: :muscle: :muscle:

1 Like