1

I'm creating NFT using metaplex library in Javascript. I need to enforce royalty on my NFT but can't find any resource that explains how to achieve this. Can someone help find a solution?

This a the function I wrote that creates an NFT:

async function createNFT(connection, privateKey, nftSymbol, nftName, description, imagePath, imageType, imageName, attributes, collection, creators) {
    const secret = bs58.decode(privateKey)
    const fromWallet = web3.Keypair.fromSecretKey(new Uint8Array(secret));
    const MPX = Metaplex.Metaplex.make(connection).use(Metaplex.keypairIdentity(fromWallet)).use(
        Metaplex.bundlrStorage({
            address: 'https://devnet.bundlr.network',
            providerUrl: SOLANA_CLUSTER_URL,
            timeout: 60000,
        })
    );
    const imageBuffer = fs.readFileSync(imagePath);
    const imageMetaplexFile = Metaplex.toMetaplexFile(imageBuffer, imageName);
    const imageUri = await MPX.storage().upload(imageMetaplexFile);
    console.log("image uri:", imageUri);
    const metadataUri = await MPX.nfts().uploadMetadata({
        name: nftName, description: description,
        image: imageUri,
        attributes: attributes,
        properties: {
            // creators: creators,
            files: [
                {
                    type: imageType,
                    uri: imageUri,
                },
            ]
        },
        collection: collection
    });
    console.log(metadataUri);
    if (creators == null || creators.length == 0) {
        creators = [
            {address: fromWallet.publicKey, share: 100}
        ]
    } else {
        creators = creators.map((c) => ({ address: new web3.PublicKey(c.address), share: c.share }))
    }
    const generatedNft = await MPX.nfts().create({
        uri: metadataUri.uri,
        name: nftName,
        symbol: nftSymbol,
        sellerFeeBasisPoints: 500,
        creators: creators,
        isMutable: true,
        isCollection: true,
    });
    console.log(generatedNft);
    return generatedNft;
}

1 Answer 1

1

Royalties are a big open question, but there's a few options out there.

  • it's possible to keep your token frozen by some program, so that transfers must go through your program to assess the royalty fee before unfreezing the token, doing the transfer, and re-freezing the token
  • if you're using token-2022, you can use a "transfer hook" program which assesses the royalty for your NFT. You can read more about it at https://spl.solana.com/token-2022/extensions#transfer-hook
1
  • As far as I know we can enforce royalties using pNFTs, but I don't know how to do it. Can you guide me about it? Commented Feb 27 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.