0

I have a contract Main that I use for selling my NFT. Here is my buy function:

function buyNFT(uint256 _id) external payable {
        require(isNFTFree(_id));
        require(msg.value == price);
        nft[_id] = msg.sender;
}

I also have a withdraw function:

    function withdraw() external onlyOwner {
        owner.transfer(address(this).balance);
    }

Now I want to create an auction system that would allow my users to auction their NFT.

So I create an "auction" contract that inherits from my Main contract

But there is one problem: I would need to store the bidders money in the balance of my contract. But is the balance the same from Main and the inherited contract "auction"? If that is the case, I will break all the auctions by withdrawing the money.

Is it better in my "buyNFT" function to directly transfer the money to the "owner" wallet?

0

There was just today a similar question about inheritance: https://ethereum.stackexchange.com/a/109767/31933 . Basically inheriting A from B (A is B) means that the compiler will simply include the code of B inside contract A (with some minor fixes for overriding stuff). So there will be only one contract to deploy. Therefore there will also be just one native asset balance for the contract.

I don't see why couldn't your buyNFT function transfer the assets directly to the owner wallet, if that's where they are supposed to end up.

Also remember that you can't inherit already deployed contracts - you can only deploy new instances.

1
  • Thank you very much :)
    – Lockface
    Sep 12 '21 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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