Using Crossmint’s minting infrastructure with your own smart contract
Crossmint has a pre-audited library of smart contracts that serve most use cases. However, if you have custom needs, you can also bring your own contract and leverage Crossmint’s scalable infrastructure to mint and distribute the NFTs. Crossmint will execute transactions at the maximum rate the blockchain can handle, pay gas fees, and create wallets for users who don’t have one, all with enterprise SLAs and customer support.
Certain API functionality may not be available with custom contracts, unless Crossmint supports those functions and
is granted permission on the contract to execute them.
This guide only applies to EVM chains. Contact us is you have custom needs in other chains.
Bringing your own contract is a premium feature. To activate it, contact
us
Your minting contract must have a function that allows free mints. This function must whitelist one of Crossmint’s treasury addresses. Contact us to obtain the wallet address to whitelist.
NFTs must follow the ERC721 standard. For ERC1155 support, contact us.
The recommendation is to use Open Zeppelin’s auditedAccessControl contract to manage the authorization logic. Here is a very basic abbreviated example:
Solidity - Access Control
// SPDX-License-Identifier: MITpragmasolidity^0.8.9;import"@openzeppelin/contracts/access/AccessControl.sol";...contractBYOCMinteris ERC721, AccessControl {bytes32publicconstant MINTER_ROLE =keccak256("MINTER_ROLE");constructor()payableERC721("EVM 721 Starter","XMPL"){_grantRole(MINTER_ROLE, msg.sender);// THIS IS THE IMPORTANT DETAIL. YOUR CROSSMINT ENGINEER WILL PROVIDE THE WALLET ADDRESS_grantRole(MINTER_ROLE,<ENTER_WALLET_PROVIDED_BY_CROSSMINT_TEAM>);}functionmint(address _to,stringcalldata uri)externalonlyRole(MINTER_ROLE){// mint function logic}}
On the console, go to the "Collections" tab and click on New collection. Next, follow the steps in the wizard to enter your contract details and identify the function used to mint NFTs. Refer to the section below for common advanced scenarios when importing your contract.
When you compile your smart contract there will be a corresponding abi file with an .abi or .json extension.
Inside this file, you'll see JSON property named abi, which describes the functions in your smart contract. Here's an example of a very simple abi file. Yours will likely have more function descriptions.
// Example generated abi file for smart contract{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"mintTo","outputs":[],"stateMutability":"payable","type":"function"}]}
Copy the JSON array object that comes after the string abi and paste it into the Contract ABI text box in the developer console. The content you paste in should begin with [ and end with ].
Whether your ABI was retrieved automatically or you pasted it in manually you need to specify the:
Mint function
Recipient address parameter name
[Optional] Quantity of NFTs to mint parameter name
Crossmint will attempt to automatically select these values for you, but it's important to ensure they are set correctly. Especially if you're setting up a USDC mint function as the list of options will be longer.
Proxy contracts are an advanced feature. Utilize this only if you're certain your contracts adhere to this pattern. This is crucial because Crossmint requires the actual NFT contract address when you register a mint/buy/purchase/claim function in a sales contract or revenue splitter.
If you don't specify the NFT contract address, our system won't be able to extract token URI information or facilitate transfers. Set this up only if it isn't a transparent proxy, which is common for upgradeable contracts.
Copy the collectionID from the collection page in the Crossmint console and share it with your Crossmint point of contact. The team will validate the contract meets the requirements, set it up to be used with the minting tools, and provide you a new collectionID which you can use to make calls to the API.
You can now invoke any of the “minting” functions documented in the API reference. Contact us if you need access to any other function, like editing or burning.
The body of the request should follow this structure:
{"recipient":"<chain>:<address>",// or <email:<email_address>:<chain>"contractArguments":{// JSON object with the arguments to the mint function and specified value}}
Ensure you are passing all parameters needed to call your mint function, except for the one specifying the
recipient, which is populated by Crossmint.