NFT Smart Contracts

NFT Smart Contracts

The core of every NFT project is a Smart Contract, which holds all the information about your NFT collection on-chain. Magic's Minting and Delivery API and NFT Checkout services support ERC-721 and ERC-1155 contracts on Polygon, but still require some specific implementation details.

This guide will walk you through setting up your smart contract for integration with Magic NFT Minting + Delivery and NFT Checkout.

#Smart Contract Requirements

In order to integrate with Magic NFT Minting + Delivery or NFT Checkout, 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 {}
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:


Grant permission to the following Magic Wallet Addresses based on your NFT Contract Type:

Polygon Mainnet

Standard ERC721 or ERC1155: 0x17C5e0af7D75F8d6e3dEf32E89dBE572788F4D77

Voucher-based ERC721: 0x5F3efD531A6883bDfFef007908155857B5faf817

Polygon Mumbai Testnet

Standard ERC721 or ERC1155: 0x9f7C3c3721B5B082924D260C3DB4e8885a874471

Voucher-based ERC721: 0xb0abb2FB5e7B2F5786CE3D1ce7bfEe676299a310

Finally, you need to verify your contract on Polygonscan, for example using Hardhat. 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("<>", {
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  })
22const magic_json = await magic_resp.json()
23const request_id =['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

#Next Steps

Once you have your contract deployed, and Magic has registered it in our backend, you can continue to integrate the Minting and Delivery API or the NFT Checkout service.