Using a Public Address Account (PDA) in accounting program
In the Solana ecosystem, the program of the programmical public address (PDA) allows for security transfers and efficient transmission management. However, when it comes to using such an account in another program or application, it must be me.
background
PDA is a public document that can be registered with every program to be adopted. However, not all programs allow trips from their PDA accounts. To solve this problem, wet to consider how from AxDrawal processes and what will sleep in another program.
Choice process
When in the Solan Crese and the PDA account, they occupy the following steps:
- The program will transport the PDA account using its towing walls.
- Whey Auser with Surrews from their PDA account, with the center of PDA account program.
- The PDA program charges them with him, they are his private keys that allow it.
problem
Now let’s consider how he was attributed to the Awelist in Awelist for a white base that allows for accommodation to the accommodation specificator. This requires a certain setting and configuration of assignment:
- The PDA account must be configured to receive the original program.
- The original program must be the function of WhiteliSising Service, which is a collection, must be given using the public account PDA.
- Whether Auser Acettes to the Weser Libs Weir PDA account, the following steps occupy:
and. The user of the Amissia Initiative and submits to it.
b. The original program has configured the PDA account, the Illladrawal transaction will be with its private key.
Solution
To solve this edition, we have implemented the most important AllLows that you will be able to do to stab. Here is one possible access:
- Introduction New Walest on the original program provided by PDA Likeddress.
- Configure a new wallet to accept the private key of the original program program.
- When the account is created in the original Attampts to Will-Fond, you do not have a new PDA new Wale to sign them.
Example code
Here is stupid excessive how to implement from this cover bed using Solan SDK:
“ Type Crip
Import {foreign, program} from “@solan/web3.js”;
Import {spltokenprogram} turned off ‘./spl token program’;
Const Original Program = new program (SPLTOENPROGGRAM, “Original_program”);
Const Newsy = New Account (“New_wallet”, “New_wallet_adddress”);
Async function with Auble Sallyfunds (Account: Account) {
// Get a private key
Const Privatekey = Acait Account.Ggetprivate ();
or
Const New Program = New Program (SplTotenprogram, “New_wallet program”));
Const Newwalletaddress = AWAIT Newprogram.CreateaCCount (Privatekey);
// sign through the extrawal transaction My
Const Soudletransction = {
to act,
AMONT: Spltokenprogram.amount,
};
Const Signransction = AWAIT Original Program.Signtransction (DownloadsTransction, Privatekey);
// Sent-Subscribed Transactions to them
Expect Original Program.
}
// Osage:
Const Newwallet = AWAIT Original Program.newwallet ();
Newwalletprogram = AWAIT New.CreateACount (Newwalletaddress);
Choose Funds (Original Program.