How can I set the price of the NFT on the NEAR blockchain (using near-contract-standards library traits for minting), so that it could be placed somewhere in metadata in order to be compliable with NEP 171 standard?
Generally, the price is set in a marketplace contract. You can do this in a number of ways but what I've seen done is that the marketplace keeps track of a sale
struct which has the token_id
, contract_id
, and price_in_near
.
The workflow would be that a user on the NFT contract approves the marketplace to transfer the token on their behalf (as per the approval management standard extension). In that approval call, the user passes in sale conditions which are relayed to the marketplace contract via a cross contract call.
The marketplace contract then stores all the information in a sale
struct. Someone else can then go to the marketplace contract and purchase the NFT by which the marketplace contract will then do a cross contract call to the NFT contract asking for how the payouts should be calculated for that token given the price that the buyer offered (these payouts are based on the royalties that were set when the token was minted and the royalties are stored in the token
struct along with the metadata and other information on the NFT contract).
The NFT contract then transfers the token to the buyer and sends back a payout map to the marketplace contract (as per the royalty payout standard extension).
The marketplace contract then takes the payout map and actually pays everybody and the sale is taken down.
If you'd like an example repository that contains all of these contracts, be sure to check out this repo here.