This part details the step-by-step algorithm for implementing a Solidity Solang program for NFT minting and transfer, where the NFT mint authority is a Program Derived Address (PDA).
illustration
b
Design Algo For Program
  1. Import Required Libraries:

    • Incorporate essential Solang Solidity libraries to make your smart contract compatible with Solana's blockchain.
  2. Setup Program ID and Contract Initialization:

    • Define a unique program ID to identify your Solang contract.
    • Initialize the contract with the necessary parameters and settings.
  3. Set Bump Using Solang Solidity Annotations:

    • Employ Solang's annotation feature to assign a 'bump' value. This value is crucial for generating off-curve Program Derived Addresses (PDAs).
  4. Setup Seed with String Literal:

    • Define a seed using a string literal. This seed will be used in conjunction with the program ID to create a PDA.
  5. Setup Payer for Constructor Calls and Contract Calls:

    • Designate the payer account responsible for transaction fees and creating new accounts in both constructor and subsequent contract calls.
  6. Constructor Body:

    • Utilize the try_find_program_address method from Solang documentation to derive a PDA.
    • Destructure the returned values to get the PDA address and bump.
    • Store the bump in a contract storage variable.
    • Verify the bump value for consistency and assign constructor parameters to contract storage variables appropriately.
  7. Mint Account Setup:

    • Establish a mint account for your NFT using methods provided by the Spl Token program library, like Spltoken.create_mint.
  8. Token Metadata Account Setup:

    • Implement methods from the Metaplex library to create a metadata account. Ensure these methods are signed with the PDA.
    • Populate the token's basic data and create a structured instruction.
    • Manually prepare the account meta instructions, set the program discriminator, and encode the instruction data for the Metaplex program call.
  9. Mint NFT to User Wallet:

    • Generate an associated token account for the user using Spltoken.create_associated_token_account.
    • Implement a modified mint_to method to enable signing with the PDA.
    • Derive and validate the PDA, prepare the instruction data, write account meta instructions, and invoke the external Spl Token program.
  10. Remove Mint Authority:

    • Implement methods to revoke the mint authority. Ensure these methods require the mint signer's presence to validate the process.

User NFT Transfer Process:

  • Develop an external function to facilitate NFT transfers. This function should contain the Spl Token transfer CPI (Cross-Program Invocation) call.
  • Include three key accounts in the function: the sender's token account (NFT sender), the receiver's token account (NFT buyer), and the owner account (transaction signer).
  • The transfer amount should be set to one for NFTs, signifying the transfer of a single, unique token.
  • The algorithm outlines the creation and transfer of NFTs, where the minting authority is a PDA. This approach allows for secure and controlled minting of NFTs and their subsequent transfer between users.
  • Freeze Authority: This authority can freeze tokens within a wallet, preventing the owner from moving, transferring, or selling them. This is akin to creating non-transferable or 'soul-bound' tokens.

  • Mint Authority: The mint authority is required to endorse transactions that generate (mint) new tokens. For example, if you initially mint 10 tokens of 'TokenX', the mint authority can later approve the creation of additional tokens, thus increasing the total supply of 'TokenX'.