README.md
6.32 Kb · 309 lines
Gnoland NFT Marketplace
A fully-featured NFT marketplace for Gnoland blockchain with automatic royalty distribution (GRC-2981 compliant).
Features
- GRC-721 compatible - works with any NFT collection implementing the standard
- Automatic royalties - supports GRC-2981 with automatic distribution
- Fixed price listings for immediate purchase
- Secure atomic transfers
- Configurable marketplace fees (default 2.5%)
- Complete on-chain sales history
- Volume and royalty statistics
Architecture
Marketplace Realm
├── Listings (Active)
├── Sales (History)
└── Payment Distribution
├── Seller
├── Royalty (if GRC-2981)
└── Marketplace Fee
NFT Collection (GRC-721)
├── OwnerOf()
├── TransferFrom()
├── Approve() / SetApprovalForAll()
└── RoyaltyInfo() (optional)
Usage
For Sellers
Step 1: Approve the Marketplace
1# Approve for all NFTs (recommended)
2gnokey maketx call \
3 -pkgpath "gno.land/r/[username]/MYNFT" \
4 -func "SetApprovalForAll" \
5 -args "g1marketplace_address" \
6 -args "true" \
7 -broadcast \
8 yourkey
9
10# Or approve for a specific NFT
11gnokey maketx call \
12 -pkgpath "gno.land/r/[username]/MYNFT" \
13 -func "Approve" \
14 -args "g1marketplace_address" \
15 -args "1" \
16 -broadcast \
17 yourkey
Step 2: Create a Listing
1gnokey maketx call \
2 -pkgpath "gno.land/r/pierre115/gnopensea" \
3 -func "CreateListing" \
4 -args "mynft.Getter()" \
5 -args "1" \
6 -args "5000000" \
7 -broadcast \
8 yourkey
Parameters:
nftGetter: Function returning the NFT collection instancetokenId: Token ID to sellprice: Price in ugnot (5000000 = 5 GNOT)
Step 3: Manage Listing
1# Update price
2gnokey maketx call \
3 -pkgpath "gno.land/r/pierre115/gnopensea" \
4 -func "UpdatePrice" \
5 -args "1" \
6 -args "10000000" \
7 -broadcast \
8 yourkey
9
10# Cancel listing
11gnokey maketx call \
12 -pkgpath "gno.land/r/pierre115/gnopensea" \
13 -func "CancelListing" \
14 -args "1" \
15 -broadcast \
16 yourkey
For Buyers
1gnokey maketx call \
2 -pkgpath "gno.land/r/pierre115/gnopensea" \
3 -func "BuyNFT" \
4 -args "1" \
5 -send "5000000ugnot" \
6 -broadcast \
7 yourkey
Purchase process:
- Payment verified
- Royalties calculated (if GRC-2981 supported)
- Payments distributed
- NFT transferred
- Excess refunded
For Admins
1# Set marketplace fee (in basis points: 100 = 1%, max 1000 = 10%)
2gnokey maketx call \
3 -pkgpath "gno.land/r/pierre115/gnopensea" \
4 -func "SetMarketplaceFee" \
5 -args "500" \
6 -broadcast \
7 adminkey
8
9# Withdraw accumulated fees
10gnokey maketx call \
11 -pkgpath "gno.land/r/pierre115/gnopensea" \
12 -func "WithdrawFees" \
13 -broadcast \
14 adminkey
Functions Reference
Public Functions
CreateListing(nftGetter, tokenId, price)- List an NFT for saleBuyNFT(listingId)- Purchase a listed NFTCancelListing(listingId)- Cancel your listingUpdatePrice(listingId, newPrice)- Update listing price
Read Functions
GetListing(listingId)- Get listing detailsGetSale(saleId)- Get sale detailsGetActiveListingsCount()- Number of active listingsGetTotalSales()- Total sales countGetTotalVolume()- Total volume tradedGetTotalRoyaltiesPaid()- Total royalties distributedGetRoyaltyBreakdown(listingId)- Calculate payment distributionGetBalance()- Marketplace balanceGetMarketplaceFee()- Current fee (basis points)GetMarketplaceAddress()- Marketplace realm address
Admin Functions
SetMarketplaceFee(newFee)- Update marketplace feeWithdrawFees()- Withdraw accumulated fees
Payment Distribution
Example with 10% royalty:
Sale Price: 100 GNOT
├── Marketplace Fee (2.5%): 2.5 GNOT
├── Creator Royalty (10%): 10 GNOT
└── Seller Receives: 87.5 GNOT
Example without royalty:
Sale Price: 100 GNOT
├── Marketplace Fee (2.5%): 2.5 GNOT
└── Seller Receives: 97.5 GNOT
Complete Workflow Example
1# 1. Deploy NFT collection
2gnokey maketx addpkg \
3 --pkgpath "gno.land/r/alice/mycollection" \
4 --pkgdir "./mycollection" \
5 --broadcast \
6 alice
7
8# 2. Mint an NFT
9gnokey maketx call \
10 -pkgpath "gno.land/r/alice/mycollection" \
11 -func "Mint" \
12 -send "1000000ugnot" \
13 -broadcast \
14 alice
15
16# 3. Approve marketplace
17gnokey maketx call \
18 -pkgpath "gno.land/r/alice/mycollection" \
19 -func "SetApprovalForAll" \
20 -args "g1marketplace_address" \
21 -args "true" \
22 -broadcast \
23 alice
24
25# 4. List for 5 GNOT
26gnokey maketx call \
27 -pkgpath "gno.land/r/pierre115/gnopensea" \
28 -func "CreateListing" \
29 -args "mycollection.Getter()" \
30 -args "1" \
31 -args "5000000" \
32 -broadcast \
33 alice
34
35# 5. Purchase NFT
36gnokey maketx call \
37 -pkgpath "gno.land/r/pierre115/gnopensea" \
38 -func "BuyNFT" \
39 -args "1" \
40 -send "5000000ugnot" \
41 -broadcast \
42 bob
Querying Data
1# View marketplace home
2curl https://test4.gno.land/r/demo/marketplace:
3
4# View statistics
5curl https://test4.gno.land/r/demo/marketplace:stats
6
7# View specific listing
8curl https://test4.gno.land/r/demo/marketplace:listing/1
9
10# View sale details
11curl https://test4.gno.land/r/demo/marketplace:sale/1
Security Features
Built-in Protections
- Ownership verification before listing and sale
- Approval checks at listing and sale time
- Payment validation with automatic refunds
- Atomic transactions (all-or-nothing)
- Admin fee limits (0-10%)
Best Practices
Do:
- Verify listing details before purchasing
- Use
SetApprovalForAll()for easier management - Check marketplace fee before listing
- Verify royalty percentages
Don't:
- Send more than listing price (wastes gas)
- List NFTs you don't own
- Forget to approve marketplace
NFT Collection Integration
Minimal Requirements
1import "gno.land/p/demo/grc/grc721"
2
3var nft *grc721.basicNFT
4
5func init() {
6 nft = grc721.NewBasicNFT("MyCollection", "MC")
7}
8
9func Getter() grc721.NFTGetter {
10 return nft.Getter()
11}
With Royalties (Optional)
1var nft *grc721.royaltyNFT
2
3func init() {
4 nft = grc721.NewNFTWithRoyalty("MyCollection", "MC")
5}
6
7func Mint() {
8 // ... mint logic
9 royaltyInfo := grc721.RoyaltyInfo{
10 PaymentAddress: creator,
11 Percentage: 10, // 10%
12 }
13 nft.SetTokenRoyalty(tokenId, royaltyInfo)
14}
15
16func Getter() grc721.NFTGetter {
17 return nft.Getter()
18}