我正在尝试使用@solana-web3 调用 Solana 智能合约上的特定端点,但我不知道如何做到这一点。我已经看到它是这样完成的:
const buffer = Buffer.from("hello");
const instruction = new web3.TransactionInstruction({
keys: [{ pubkey: fromWallet.publicKey, isSigner: false, isWritable: true }],
programId: new web3.PublicKey(metaDataProgramID),
data: buffer,
});
const confirmation = await web3.sendAndConfirmTransaction(
connection,
new web3.Transaction().add(instruction),
[fromWallet],
{
commitment: "singleGossip",
preflightCommitment: "singleGossip",
}
);`
但我不确定如何处理这样的具有多个端点的智能合约。因为如何告诉智能合约使用哪个端点以及将什么数据传递给该端点?:
pub fn process_instruction<'a>(
program_id: &'a Pubkey,
accounts: &'a [AccountInfo<'a>],
input: &[u8],
) -> ProgramResult {
let instruction = MetadataInstruction::try_from_slice(input)?;
match instruction {
MetadataInstruction::CreateMetadataAccount(args) => {
msg!("Instruction: Create Metadata Accounts");
process_create_metadata_accounts(
program_id,
accounts,
args.data,
false,
args.is_mutable,
)
}
MetadataInstruction::UpdateMetadataAccount(args) => {
msg!("Instruction: Update Metadata Accounts");
process_update_metadata_accounts(
program_id,
accounts,
args.data,
args.update_authority,
args.primary_sale_happened,
)
}
MetadataInstruction::DeprecatedCreateMasterEdition(args) => {
msg!("Instruction: Deprecated Create Master Edition");
process_deprecated_create_master_edition(program_id, accounts, args.max_supply)
}
MetadataInstruction::DeprecatedMintNewEditionFromMasterEditionViaPrintingToken => {
msg!("Instruction: Deprecated Mint New Edition from Master Edition Via Token");
process_deprecated_mint_new_edition_from_master_edition_via_printing_token(
program_id, accounts,
)
}
MetadataInstruction::UpdatePrimarySaleHappenedViaToken => {
msg!("Instruction: Update primary sale via token");
process_update_primary_sale_happened_via_token(program_id, accounts)
}
MetadataInstruction::MintNewEditionFromMasterEditionViaVaultProxy(args) => {
msg!("Instruction: Mint New Edition from Master Edition Via Vault Proxy");
process_mint_new_edition_from_master_edition_via_vault_proxy(
program_id,
accounts,
args.edition,
)
}
MetadataInstruction::PuffMetadata => {
msg!("Instruction: Puff Metadata");
process_puff_metadata_account(program_id, accounts)
}
}
}
这是智能合约的完整代码:https ://github.com/metaplex-foundation/metaplex/tree/master/rust/token-metadata/program