NFT Minting
NFT Minting
#Minting With Magic ✨
With Magic’s NFT minter, you can easily mint and airdrop NFTs on-demand via a single API call. Our service handles NFT minting at scale, all end-user gas fees, and is compatible with ERC-721 and ERC-1155 contracts on Polygon.
To get early access to this feature, please fill out this form and our team will be in touch shortly.
#Benefits
- Scalable: Our infrastructure and aggregator contract allow us to efficiently bundle multiple transactions together, making it possible to handle large user loads with ease.
- Gasless: It's not necessary for either customers or end users to have any crypto in order to get a NFT and use this service. Magic automatically handles all gas fees required for minting and is designed for efficient and cost-effective high throughput.
#Use Cases
Airdrops: Easily let your users claim, mint or directly receive free NFTs.
Delivery for fiat NFT purchases: Our minter tool can be easily integrated with any payment provider you prefer. It allows you to collect payments off-chain in fiat and securely deliver the NFT once the payment is confirmed. You can make the purchase process even more seamless with our pre-built checkout solution that includes both on and off ramp rails for fiat to NFT direct purchases. Please note that the checkout feature is coming soon.
#Usage
Currently we only support our minting service on Polygon. If you are interested in other EVM based chains, please contract your customer success representative.
#Smart Contract Requirements
In order to utilize the minter, developers must construct and deploy their own NFT smart contract, which can either be an ERC721 or ERC1155 contract. However, it is crucial to incorporate a minting function that follows the specified standards outlined below.
#Required Function
01// ERC721
02function mint(address _userWallet, uint256 _quantity) external payable {}
03
04// ERC1155
05function mint(address _userWallet, uint256 _quantity, uint256 _tokenId) external payable {}
If you’ve already deployed your contract and it does not match the above, reach out to Magic Support, there may be ways to interface between Magic and your contract.
Next, if you have minting restrictions on your contract, you need to grant permission to Magic’s address to be able to mint. For example, if you’re using Open Zeppelin’s Access Control library you might run something like:
01contract_instance.functions.grantMinter('0x42DB2457322fC53A5...');
Grant permission to the following Magic Wallet Addresses based on your NFT Contract Type:
Standard ERC721 or ERC1155: 0x17C5e0af7D75F8d6e3dEf32E89dBE572788F4D77
Voucher-based ERC721: 0xd2616C451D63681862Fd9A2d3CbcB0e40D005953
Finally, you need to verify your contract on Polygonscan. This allows our support team to review your contract and help if needed.
#Voucher Based Minting
The minting service can optionally support voucher-based minting. This allows for additional rules to be added before fulfilling the mint request. Integrating this feature requires some additional work with our customer success team, please reach out to your rep to learn more.
01const magic_resp = await fetch("<https://nft-api.magic.link/v1/nft/voucher/start_mint>", {
02 method: "POST",
03 headers: {
04 "Content-Type": "application/json",
05 "X-Magic-Secret-Key": <sk_live_xxxxxxx>,
06 },
07 body: JSON.stringify({
08 contract_id: <contract_id>,
09 quantity: int,
10 destination_address: str,
11 voucher: {
12 "buyer": "0x2CBC8df69CA34F26Db371fb9380c90Ab91bd7A55",
13 "expirationDuration": 172800,
14 "issueTime": 1681160264,
15 "nonce": 288067592000,
16 "pricePerToken": 0,
17 "signature": "0xABCD"
18 }
19 })
20})
21
22const magic_json = await magic_resp.json()
23const request_id = magic_json.data['request_id']
#Submitting Details to Magic
Once you have your contract deployed, send the following details to your Magic Customer Success rep:
- Publishable API Key (from any app in your Magic dashboard)
- Contract Address
- Minting function name
- Webhook URL for minting and delivery status updates - see section below
#Getting Started
To get started with NFT Minting and Delivery, you must first sign in or sign up and create a application (Magic Connect or Magic Auth) through Magic's dashboard. Once you’ve submitted the information above and Magic has configured your contract, you are ready to start minting!
Save the following pieces of information for the section below:
- Your secret key to be used to make API calls (you can find on the homepage of any app on your dashboard as shown in the image below).
- Your contract ID that will be provided by your Magic Customer Success rep for each contract your deploy
#Endpoints
Depending on your contract type you can hit one of two endpoints:
- ERC721: https://api.magic.link/v1/admin/nft/mint/721_mint
- ERC1155: https://api.magic.link/v1/admin/nft/mint/1155_mint
Javascript Example
Replace <sk_live_xxxxxxx>
with your secret key and contract_id
with the one provided by your rep.
For ERC-1155 mints:
01const magic_resp = await fetch("<https://api.magic.link/v1/admin/nft/mint/1155_mint>", {
02 method: "POST",
03 headers: {
04 "Content-Type": "application/json",
05 "X-Magic-Secret-Key": <sk_live_xxxxxxx>,
06 },
07 body: JSON.stringify({
08 contract_id: <contract_id>,
09 token_id: int,
10 quantity: int,
11 destination_address: str,
12 })
13})
14
15const magic_json = await magic_resp.json()
16const request_id = magic_json.data['request_id']
For ERC-721 mints:
01const magic_resp = await fetch("<https://api.magic.link/v1/admin/nft/mint/721_mint>", {
02 method: "POST",
03 headers: {
04 "Content-Type": "application/json",
05 "X-Magic-Secret-Key": <sk_live_xxxxxxx>,
06 },
07 body: JSON.stringify({
08 contract_id: <contract_id>,
09 quantity: int,
10 destination_address: str,
11 })
12})
13
14const magic_json = await magic_resp.json()
15const request_id = magic_json.data['request_id']
Once the NFT Minting Request has been submitted, these requests will return. However, it may take a few minutes to process them. When a minting request succeeds or fails, Magic will call the webhook that you provided during setup.
#Webhook Setup
To determine if NFT minting has succeeded or failed, you must set up a webhook endpoint on your backend. Our team will configure these during the onboarding process. This endpoint can be named anything and can accept any static parameters, but it must meet the following requirements:
- Accept POST requests
- Return a 200 response for both success and failure notifications
Example Webhook POST Requests
01// Success
02{
03 "status": "ok",
04 "request_id": "abcd1234",
05 "message": "Mint was successful!"
06}
07
08// Failure
09{
10 "status": "error",
11 "request_id": "abcd1234",
12 "message": "Mint failed during the minting step - please reach out to Magic support"
13}