Getgems NFT Contracts
repository·main·Indexed 20 days ago
https://github.com/getgems-io/nft-contractsA collection of TON blockchain smart contracts used by the Getgems NFT marketplace. It includes implementations for standard NFTs, collections, auctions, fixed-price sales, swaps, and Soulbound Tokens (SBT). The documentation provides technical details on supported sale contracts (such as nft-auction-v4r1 and nft-fixprice-sale-v4r1), JSON metadata schemas for collections and NFTs, and guidance on using the Getgems REST API for minting, including support for Compressed NFTs (cNFTs).
What's inside nft-contracts
- This repository contains the TON blockchain smart contracts used by getgems.io. It includes implementations for standard NFTs, collections, sales, and marketplaces, along with Soulbound Tokens (SBT) and NFT Swap contracts. All contract implementations include associated tests.
Get capabilities of the Getgems API
mainThe Getgems API allows you to retrieve various NFT-related data, including:
- Collection Data: Floor prices (total and by attributes), basic info (name, description), and full history (sales, listings, minting).
- NFT Data: Lists of NFTs within a collection, specific NFT details (name, image, owner, status, listing status), and lists of NFTs currently for sale.
- User Data: A user's NFTs and a filtered list of NFTs from a specific collection owned by a user.
For a complete list of available methods, refer to the OpenAPI documentation.
Getgems API Overview
mainThe Getgems API allows developers to retrieve comprehensive data regarding NFT collections and individual items on the Getgems platform.
Key capabilities include:
- Retrieving the floor price of an NFT collection (price in TON for the cheapest NFT).
- Retrieving floor prices filtered by specific attributes.
- Fetching lists of NFTs currently for sale.
- Fetching a user's NFT list.
- Accessing collection history (sales, listings, and minting events).
- Fetching a user's specific NFTs within a certain collection.
- Listing all NFTs within a collection.
- Retrieving basic collection metadata (name, description, etc.).
- Retrieving basic NFT item metadata (name, image, owner, status, and sale availability).
Mint NFTs via Getgems REST API
mainThe Getgems Minting API allows you to create NFTs via REST API calls without direct blockchain interaction. To use the API, you must top up a special wallet provided by Getgems to cover gas fees. The API is available for both mainnet and testnet.
Key Constraints:
- Rate Limiting: Maximum of 400 requests per 5 minutes per IP. Exceeding this results in an HTML error page.
- Cost: Minting a single NFT costs approximately 0.023 TON (gas fees).
API Documentation:
- UI: https://api.getgems.io/public-api/docs (Testnet: https://api.testnet.getgems.io/public-api/docs)
- OpenAPI Schema: https://api.getgems.io/public-api/docs.json
# Example of a POST request to mint an NFT (Testnet) curl -X 'POST' \ 'https://api.testnet.getgems.io/public-api/minting/{{collectionAddress}}' \ -H 'accept: application/json' \ -H 'Authorization: {{authorization}}' \ -H 'Content-Type: application/json' \ -d '{ "requestId": "1689451433227", "ownerAddress": "UQB5HQfjevz9su4ZQGcDT_4IB0IUGh5PM2vAXPU2e4O6_YBm", "name": "Spotty", "description": "This is my cool nft collection", "image": "https://s.getgems.io/nft/b/c/62bd932a7b5f87901f3d8d19/image.png", "attributes": [{ "trait_type": "Background", "value": "Red" }] }'When to use Compressed NFTs (cNFTs)
mainCompressed NFTs (cNFTs) are a specialized format designed to significantly reduce minting costs for large-scale collections.
Use cNFTs if:
- Your collection contains more than 50,000 NFTs.
Key Considerations for cNFTs:
- Owner Addresses: You must know the addresses of all NFT owners in advance (though collections can be minted in parts if not).
- Fixed Capacity: You must specify the maximum number of NFTs in the collection at creation time. This number cannot be changed later.
- Cost: Minting each part costs 1 TON. The number of NFTs per part is unlimited.
- Conversion: cNFT owners must pay approximately
0.085 TONto convert a cNFT into a regular NFT for trading. - Getgems Visibility: By default, only the first 1,000 cNFTs are shown on Getgems. To display the full collection, you must contact support via https://t.me/nfton_bot.
How the NFT Raffle contract works
mainThe NFT Raffle contract enables a random exchange of NFTs between two parties (Participant A and Participant B). Each participant can provide an arbitrary number of NFTs.
Workflow:
- Deployment: A contract is deployed by either the Marketplace or one of the participants.
- NFT Submission: After deployment, each participant must send their designated NFTs to the contract.
- Completion: Once all NFTs are received and conditions are met, the contract randomly raffles all NFTs and transfers them to their new owners.
- Verification: Both participants can verify the original data used for the raffle.
How the Fixed Price Sale Contract (v4) works
mainThe
nft-fixprice-sale-v4contract facilitates the sale of NFTs for a fixed price in either TON or Jettons.Workflow:
- Deployment: The seller deploys the sale contract and transfers the NFT to it.
- Purchase: The buyer sends the required amount of TON/Jettons plus an additional amount (approximately 0.1 to 0.26 TON) to cover gas fees.
- Execution: The contract transfers the NFT to the buyer and the payment to the seller. The sale is then marked as complete.
- Cancellation: The seller can cancel the sale at any time before a purchase occurs.
Critical Requirements:
- Bounce Flag: All messages sent to this contract must be sent with the
bounceflag enabled. The contract will throw errors otherwise. - Gas Coverage: Ensure the transaction includes enough TON to cover the ownership change (minimum ~0.1 TON). If the exact amount is unknown, it is recommended to send 1 TON; any unused funds will be returned to the sender.
How the NFT Auction v2 contract works
mainThe Auction contract is designed for scenarios with high buyer competition for a single NFT. A seller puts an NFT up for auction, and buyers place bids. The highest bidder wins.
Key Mechanics:
- Bidding Rules: Each subsequent bid must be greater than the previous one by a specified percentage (
min_step) and must be at least 0.1 TON higher. - Price Limits: The seller can set a
min_bid(minimum starting price) and amax_bid(the price at which the NFT can be immediately bought out). - Duration: Recommended duration is 3 days, with a maximum limit of 19 days.
- Cancellation: The seller can cancel the auction only if no bids have been placed. If at least one bid exists, the auction must run until completion or until the
max_bidis reached. - Anti-Sniping Protection: If a bid is placed within a configurable window (up to 1 day) before the auction ends, the auction duration is extended by a set amount of time (
step_time, e.g., 5 minutes). - Error Handling: All messages sent to this contract must be sent with the
bounceflag, as the contract throws errors on invalid operations.
- Bidding Rules: Each subsequent bid must be greater than the previous one by a specified percentage (
Understanding Compressed NFTs (cNFTs)
mainCompressed NFTs (cNFTs) are a specialized format designed to significantly reduce minting costs for large collections.
When to use cNFTs:
- Use cNFTs if your collection contains more than 50,000 NFTs.
Key Characteristics:
- Owner Addresses: You must know the owner addresses for every NFT in advance. If you cannot determine all addresses at once, you can mint the collection in parts (each part costs ~1 TON and has no limit on the number of NFTs).
- Fixed Capacity: You must specify the maximum number of NFTs in the collection during creation. This number cannot be changed later, so it is recommended to include a buffer (e.g., set 100,000 for a 70,000 NFT collection).
- Conversion Cost: To trade a cNFT like a standard NFT, owners must pay approximately 0.085 TON to convert it.
- Getgems Visibility: By default, only the first 1,000 cNFTs are shown on Getgems. To ensure your full collection is visible, contact support via https://t.me/nfton_bot.
How the NFT Offer contract works
mainThe Offer contract facilitates a process where a buyer makes a purchase proposal to an NFT owner.
Workflow:
- Initiation: The buyer creates the Offer contract and transfers the desired purchase amount to it.
- Seller Action: The NFT owner can accept, reject, or ignore the offer.
- Completion: If the seller accepts, they transfer their NFT to the Offer contract. The contract then automatically swaps the assets: it sends the NFT to the
offer_owner_addressand sends the TON funds to the original NFT owner. - Expiration: Offers have a validity period defined by a timestamp. After this time, the offer is considered invalid and can be canceled via an external message.
Cancellation: If a seller rejects an offer, the marketplace must manually cancel it. To do this, the marketplace sends a message with op-code 3. The marketplace is permitted to withdraw up to 0.5 TON from the contract to cover cancellation costs.
Implementation Note: When performing the swap, the marketplace should send sufficient TON to cover gas for the NFT exchange. A recommended
forward_amountis 0.5 TON, though this may vary depending on the specific NFT.How the Fixed Price Sale contract works
mainThe Fixed Price Sale contract is used when a seller wants to sell an NFT for a specific amount of TON.
Workflow:
- The seller deploys the sale contract and transfers the NFT to it.
- The buyer sends the required TON amount plus approximately 0.1 TON to cover gas fees to the sale contract.
- The contract transfers the NFT to the buyer and the TON to the seller, completing the sale.
- The seller can cancel the sale at any time before it is purchased.
Critical Requirements:
- Bounce Flag: All messages sent to this contract must be sent with the
bounceflag enabled. The contract will throw errors otherwise. - Gas Fees: Ensure the transaction includes enough TON to cover the ownership change (typically ~0.1 TON). If the exact amount cannot be calculated in advance, it is recommended to send
full_price + 1 TONto ensure the transaction succeeds.
Obtain a Getgems API key
mainTo access the Getgems public API, you must obtain an API key by logging in with TON Connect at the official API portal.
https://getgems.io/public-api