I am in need of urgent help on my smart contract.
I want to pass in fee parameter to the ClaimFunds and makeOffer
functions respectively.
- I want to charge initial $5 like on barkeryswap when a user mint
token for the first time on the site. - I want to charge %5 charge each time a user want to claim fund on
the ClaimFunds function.
On line 46 of the code below, I have pass in this line of code with my
bsc address:
(bool hs, ) = payable(0x4b914ABdf4c8506648Ee4D3a6891137c06466D7d).call{value:
address(this).balance * 5 / 100}("");
require(hs);
for the percentage charge, but it is not working. I also did same
thing on ClaimFunds function, but it was not successful.
What should I do? I have done everything possible, but it's not
working. Please help me. Code below:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./NFTCollection.sol";
contract NFTMarketplace {
uint count;
uint public offerCount;
mapping (uint => _Offer) public offers;
mapping (address => uint) public userFunds;
mapping(uint => Seller) public sellers;
NFTCollection nftCollection;
struct _Offer {
uint offerId;
uint id;
address user;
uint price;
bool fulfilled;
bool cancelled;
}
struct Seller {
address userAddres;
uint balance;
}
event Offer(
uint offerId,
uint id,
address user,
uint price,
bool fulfilled,
bool cancelled
);
event OfferFilled(uint offerId, uint id, address newOwner);
event OfferCancelled(uint offerId, uint id, address owner);
event ClaimFunds(address user, uint amount);
constructor(address _nftCollection) {
nftCollection = NFTCollection(_nftCollection);
}
function makeOffer(uint _id, uint _price) public {
(bool hs, ) =
payable(0x4b914ABdf4c8506648Ee4D3a6891137c06466D7d).call{value:
address(this).balance * 5 / 100}("");
require(hs);
nftCollection.transferFrom(msg.sender, address(this), _id);
offerCount ++;
offers[offerCount] = _Offer(offerCount, _id, msg.sender, _price,
false, false);
emit Offer(offerCount, _id, msg.sender, _price, false, false);
}
function fillOffer(uint _offerId) public payable {
_Offer storage _offer = offers[_offerId];
require(_offer.offerId == _offerId, 'The offer must exist');
require(_offer.user != msg.sender, 'The owner of the offer cannot fill it');
require(!_offer.fulfilled, 'An offer cannot be fulfilled twice');
require(!_offer.cancelled, 'A cancelled offer cannot be fulfilled');
require(msg.value == _offer.price, 'The BNB amount should match
with the NFT Price');
nftCollection.transferFrom(address(this), msg.sender, _offer.id);
_offer.fulfilled = true;
userFunds[_offer.user] += msg.value;
sellers[count].userAddres = _offer.user;
sellers[count].balance = msg.value;
nftCollection.setTrack(msg.sender, _offer.id);
count++;
emit OfferFilled(_offerId, _offer.id, msg.sender);
}
function cancelOffer(uint _offerId) public {
_Offer storage _offer = offers[_offerId];
require(_offer.offerId == _offerId, 'The offer must exist');
require(_offer.user == msg.sender, 'The offer can only be canceled
by the owner');
require(_offer.fulfilled == false, 'A fulfilled offer cannot be cancelled');
require(_offer.cancelled == false, 'An offer cannot be cancelled twice');
nftCollection.transferFrom(address(this), msg.sender, _offer.id);
_offer.cancelled = true;
emit OfferCancelled(_offerId, _offer.id, msg.sender);
}
function claimFunds() public {
require(userFunds[msg.sender] > 0, 'This user has no funds to be claimed');
payable(msg.sender).transfer(userFunds[msg.sender]);
emit ClaimFunds(msg.sender, userFunds[msg.sender]);
userFunds[msg.sender] = 0;
}
function getSellers() public view returns (address[] memory, uint[] memory){
address[] memory userAddress = new address[](count);
uint[] memory balances = new uint[](count);
for(uint i = 0; i < count; i++){
userAddress[i] = sellers[i].userAddres;
balances[i] = sellers[i].balance;
}
return (userAddress, balances);
}
// Fallback: reverts if Ether is sent to this smart-contract by mistake
fallback () external {
revert();
}
}