Solana: What is the difference between .rpc () is
.
As a Solana developer, you are probably familiar with an anchor bookstore that provides a convenient interface for interacting with Solana blockchain. Two common features that can be used to send instructions are. Although they may seem similar, there is an important difference between them.
. RPC ()
. When called
.rpc ()creates a request that can be done on Blockchain. The request contains metadata for education, such as its name, signature and topics. This metadata allows you to combine the request with existing Blockchain instructions.
Here's an example of how to use.rpc ():
Javascript
Const anchor = requirement (‘@anchor-protocol/ancors’);
// Create a new account
Const Accountid = Anchor.web3.eth.acacuns._New ();
// Determine education
CONST instructions = {
Name: “My education”,
Args: [1, 2, 3],
};
// Send the request to .rpc ()
Anchor.rpc (). Instructions ({
Address: Accountid,
Signature: “your_signure_her”,
Data: Education,
}). Then ((response) => console.log (response));
`
. Instructions ()
.Inclation () is intended to send instructions directly from a program or script. When it is called `.
Here's an example of how to use.intmentation ():
Javascript
Const anchor = requirement (‘@anchor-protocol/ancors’);
// Create a new account
Const account = Anchor.web3.eth.acounts._New ();
// Define the script
Const Script = {
Code: ‘Function () {Self.Addacacount (ACCONDID); } ‘,
};
// Send the .struction instructions ()
Anchor.rpc (). Instructions (script) .Then ((response) => console.log (response));
`
Key Differences
So, what is the key difference between.rpc () is.istrocation ()?
- Metadates :.rpc ()
Requires metadata for education, while '.ininstmentation ()
No.
- Performance
:
.rpc () is the request of blockchain, while
.is)can be done directly through a program or script.
In your case, if you send an education directly using.rpc (), it is likely that the problem is related to the way you create and perform education. Be sure to provide the right metadata, such as the address "of the account and any additional topic.
Here is an example of how to create a new education with.ininsing ()and to perform it:
Javascript
Const anchor = requirement (‘@anchor-protocol/ancors’);
// Create a new account
Const Accountid = Anchor.web3.eth.acacuns._New ();
// Define the script
Const Script = {
Code: ‘Function () {Self.Addacacount (ACCONDID); } ‘,
};
// Send the .struction instructions ()
Anchor.rpc (). Instructions (script) .Then ((response) => console.log (response));
`
In summary,. Be sure to use the right function and provide proper metadata during the creation and execution of the instructions.