Create With Signature
One of the most powerful features of the Mirror NFT Protocol is deploying NFTs with a signature from the creator, using ERC-7015 for creator attribution.
For this type of deployments, the creator needs to provide a signature of the parameters and then another wallet can deploy the token. The SDK provides all the necessary data to generate the signature and a way to deploy and collect the token in a single transaction using multicall
.
Generating Signature Data
Creating a token with a signature requires the creator to sign parameters for the NFT. To generate the parameters that will be signed, provide a token configuration to getCreateWithSignatureData
. In the example below, we create a token with a name
, a symbol
and register a fixed-sale.
import { chainId, rpcURL, creatorWalletAddress, fixedSaleConfig } from "config.ts";
import { MirrorSDK } from "@cmirrorxyz/mirror-nft-sdk";
import type { ERC721TokenConfig } from "@cmirrorxyz/mirror-nft-sdk";
const sdk = new MirrorSDK(chainId, rpcURL);
const tokenConfig: ERC721TokenConfig = {
name: "Awesome name",
symbol: "Awesome symbol",
fixedSales: [fixedSaleConfig]
};
const {
primaryType,
domain,
types,
message
} = await sdk.factory.getCreateWithSignatureData(
tokenConfig,
creatorWalletAddress
);
export const chainId: number = 31337;
export const rpcURL: string = "127.0.0.1:8545"
const creatorWalletAddress = "0x...";
export const fixedSaleConfig: FixedSaleMinterConfig = {
price: BigInt(0),
supply: BigInt(100),
start: BigInt(0),
end: BigInt(100_000_000),
tokensPerAddress: BigInt(1),
fundsRecipient: creatorWalletAddress,
};
Then primaryType
, domain
, types
, and message
can be used to sign with signTypedData. After the creator has signed the message the signature can be stored and used in the following step to deploy a token.
Creating tokens with signature
Once you generate and store a signature with the step above, it can be used to deploy a token.
import { chainId, rpcURL, creatorWalletAddress, fixedSaleConfig } from "config.ts";
import { MirrorSDK } from "@cmirrorxyz/mirror-nft-sdk";
import type { ERC721TokenConfig } from "@cmirrorxyz/mirror-nft-sdk";
const sdk = new MirrorSDK(chainId, rpcURL);
const tokenAddress = await sdk.factory.getCloneAddress(
tokenConfig,
creatorWalletAddress
);
const transactionData = await sdk.factory.getCreateWithSignatureAndPurchaseTransaction({
tokenConfig,
creator: creatorWalletAddress
signature, // Generated in the previous step.
fixedSalePurchases: [
{
token: tokenAddress,
quantity: BigInt(1),
tokenRecipient: collectorWalletAddress,
price: fixedSaleConfig.price,
}
]
});
export const chainId: number = 31337;
export const rpcURL: string = "127.0.0.1:8545"
const creatorWalletAddress = "0x...";
export const fixedSaleConfig: FixedSaleMinterConfig = {
price: BigInt(0),
supply: BigInt(100),
start: BigInt(0),
end: BigInt(100_000_000),
tokensPerAddress: BigInt(1),
fundsRecipient: creatorWalletAddress,
};
The result transactionData
will be a call to a multicall
contract, it'll execute two calls, deploying the token and collecting.
For signature mints, you will need to provide a signaturePurchases
array of type SignatureMinterPurchaseArgs
, a signaturePrivateKey
and an rpcURL
.