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