import { createRaribleSdk } from "@rarible/sdk" import { toCollectionId, toContractAddress, toUnionAddress } from "@rarible/types" import type { BlockchainWallet } from "@rarible/sdk-wallet" import { MintType } from "@rarible/sdk/build/types/nft/mint/domain" export async function mintOnChainWithTokenId(wallet: BlockchainWallet, contractAddress: string) { const sdk = createRaribleSdk(wallet, "testnet") const collectionId = toContractAddress(contractAddress) //Get tokenId for collection and mint const tokenId = await sdk.nft.generateTokenId({ collection: collectionId, minter: toUnionAddress(""), }) const mintAction = await sdk.nft.mint({ collectionId: toCollectionId(collectionId), tokenId, }) /* You should upload json file with item metadata with the following format: { name: string description: string | undefined image: string | undefined "animation_url": string | undefined "external_url": string | undefined attributes: TokenMetadataAttribute[] } and insert link to json file to "uri" field. To format your json data use "sdk.nft.preprocessMeta()" method */ const mintResult = await mintAction.submit({ uri: "", //optional royalties: [{ account: toUnionAddress(""), value: 1000, }], //optional, by default creator=minter creators: [{ account: toUnionAddress(""), value: 10000, }], lazyMint: false, supply: 1, }) if (mintResult.type === MintType.ON_CHAIN) { await mintResult.transaction.wait() return mintResult.itemId } }