4

I have a solana program to which I want to send parameters and also different accounts, however I have not found how to do it, in this case I am using this flutter/dart library.

Flutter Packages [https://pub.dev/packages/solana_web3][1]

An example of how to communicate with a solana program in this case with the memo could be like this:

 Future<void> sendDataToContract(String s) async {
    // Create a connection to the Solana devnet.
    final connection = web3.Connection(web3.Cluster.devnet);
    // Get the program id of the smart contract.
    const programId = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
    // Create the smart contract public key.
    final publicKey = web3.PublicKey.fromBase58(programId);
    final transaction = web3.Transaction();
    transaction.add(web3.TransactionInstruction(
      keys: [
        web3.AccountMeta(
          solanaMainWallet.publicKey,
          isSigner: true,
          isWritable: true,
        ),
      ],
      programId: publicKey,
      data: const Utf8Encoder().convert(s),
    ));

    // Send the transaction.
    var restul = await connection
        .sendAndConfirmTransaction(transaction, signers: [solanaMainWallet]);
    debugPrint('Tx successful with hash: $restul');
  }
}

the above code works great, but now i need to communicate with a different solana program a custom one, with a custom function, let's say in javascript it would be something like this:

const tx = await program.methods.createNft(nftMetadata.id, nftMetadata.name, nftMetadata.symbol, nftMetadata.uri, nftMetadata.price, nftMetadata.cant)
    .accounts({ mint: nftMintPda, tokenAccount: tokenAccount, metadataProgram: TOKEN_METADATA_PROGRAM_ID, masterEditionAccount: masterEditionAccountPda, payer: provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, rent: anchor.web3.SYSVAR_RENT_PUBKEY, nftMetadata: nftMetadataPdaMPL })
    .rpc()
    .catch(err => console.log(err));

in javascript to be able to access the method of the program we use "program.methods.createNft" but I don't know how to do this for flutter/dart.

final nftTransaction = web3.Transaction();
nftTransaction.add(web3.TransactionInstruction(
      keys: [
        web3.AccountMeta(
          nftMintPda.publicKey,
          isSigner: false,
          isWritable: true,
        ), //Mint account
        web3.AccountMeta(
          tokenAccount.publicKey,
          isSigner: false,
          isWritable: true,
        ),...
      ],
      programId: programIdPublicKey,
      data: args,
    ));
   
    // Send the transaction.
    var nftTxRestul = await connection.sendAndConfirmTransaction(nftTransaction, signers: [solanaMainWallet]);

If I send the transaction without specifying which method is going to be used, it returns the error:

101 (0x65) InstructionFallbackNotFound Fallback functions are not supported

1 Answer 1

3

Disclaimer, I don't have Flutter experience and I'm not familiar with the flutter library you linked, but I looked through their GH repo and see that they provide an implementation of the metaplex_token_metadata program..

I think you'll have to construct a Transaction like here, but instead of using SystemProgram you should use the MetaplexTokenMetadataProgram and TokenProgram to generate the instructions you want.

Roughly:

  1. Create a Mint Account with intializeAccount and initializeMint
  2. Create the token metadata with createMetadataAccountV3

hopefully that helps!

2
  • Thank you very much for writing, but it is similar to what I wrote, if you notice it is not just interacting with the program, when you create the solana program an IDL is generated which has the structure for you to interact with your solana program, let's say in js it is something like "program.methods.createNft(" I have to replicate the same but in flutter/dart, this initially. Jul 25, 2023 at 0:24
  • 2
    I see you found a potential answer in the Flutter/Dart discord! Re-iterating here for future clarity: To interact with Anchor Programs on Flutter use the Solana Dart library maintained by Espresso Cash. Then, reference these tests and an example of using Anchor programs in Flutter. Jul 25, 2023 at 17:25

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.