'NEAR Marketplace - How should I charge the transaction fee on each sales?
We're building a marketplace in NEAR. We have two smart contracts for token and marketplace. Same as NEAR example.
In our platform, we have successfully implemented below features:
- Token mint (used contract method:
nft_mint
) - Token listing for sale in marketplace (used contract methods:
storage_deposit
nft_approve
) - Token purchase (used contract method:
offer
)
Everything is working fine.
Now, we want to charge the transaction fee (2.5%) on each sales for our marketplace.
--
I did one mint and buy test with Paras Marketplace to observe the royalty and transaction fee distribution. Here is the test details:
With seller.near account, I minted an NFT in Paras Marketplace. And added 3% royalty. And listed it @1 Ⓝ for sale.
With buyer.near account, bought it with another account.
NFT Details:
Name : My Non-fungible token #1
Listed Price : 1 Ⓝ
Royalty : 3%
Sale Breakdown:
Receive (Seller) : 0.95 Ⓝ
Royalty (Creator) : 0.03 Ⓝ
Fee (Paras) : 0.02 Ⓝ
Before purchase - Account Balance
buyer.near : 50.03995 Ⓝ
seller.near : 4.896 Ⓝ
After purchase (1st sale after minted) - Account Balance
buyer.near : 49.03388 Ⓝ | Difference : -1.00607 Ⓝ
seller.near : 5.82587 Ⓝ | Difference : +0.92987 Ⓝ
# NFT Create Transaction
This is nft_create_series
transaction. Where Paras is sending "transaction_fee": "200"
to charge 2% service fee on each sale:
# NFT Buy Transaction
This is buy
transaction. Where Paras charged 2% service fee:
Question:
We want to charge 2.5% service fee on each sales.
We want to implement "transaction_fee": "250"
object in our marketplace contract.
How to do the same with our marketplace?
Solution 1:[1]
There are several ways that you can go about doing this. The two that I would recommend are the following (I saw you were following along with the zero to hero tutorial):
Option A (simplest) - store your account in the perpetual royalties object for the token when it is minted.
- This is the easiest to implement as you don't need to change anything in your contracts and you simply need to alter what is passed into the royalties object on mint.
- This requires that you have control over the NFT contract.
- This allows you to receive royalties on whatever marketplace the token is sold on since the royalties are stored on the token level in the NFT contract.
- This allows you to specify which account should receive the royalties instead of forcing the marketplace contract to store the funds.
Option B - before calling nft_transfer_payout
in your marketplace contract, subtract 2.5% from the price object. This will result in your marketplace contract keeping the 2.5% and paying out the remaining 97.5% to the respective accounts.
- With this approach, since many accounts are paying for storage, your contract has funds that aren't all withdraw-able by you. You should keep a tally on how much $NEAR you've received so that you can withdraw that amount and not accidentally withdraw too many funds that may have "belonged" to someone else via storage deposits.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Benjamin Kurrek |