CRYPTOCURRENCY

Solana: Can a PDA account created in a program be allowed to use in another program to sign?

Software Public Address (PDA) Account in another program

In the Sorana ecosystem, the programmatic report of the public address (PDA) enables safe and efficient control of chips. However, when you use such an account in another program, there are special requirements that need to be met.

background

PDA is a public address that any program can use to receive funds. All programs allow you to raise your PDA account. To solve this problem, we need to consider how the pension process works and what is needed to use the account in another program.

Deleting process

Solana: Can a PDA account created in a program be allowed to use in another program to sign?

When you create a PDA account in the Sorana application, the following steps are performed:

  • The program creates a PDA account with its wallet.

  • When the user removes funds from his PDA account, the lifting operation is sent to the PDA account.

  • PDA account programs sign pension operations with its private key to check the sender and the deleted amount.

problem

We now think about how the account created in the program can use the white list lifting process, which allows only the special white list addresses to raise funds. This requires some additional settings and configuration:

  • The PDA account must be determined to approve the withdrawal of the original program.

  • The original program must install a feature indicating the white list service when trying to cancel the PDA account at the public address.

  • When a user tries to raise funds in their PDA account, the following steps:

a. The user starts the pension operation and sends it to the network.

b. If the original program corrects the PDA account correctly, it will sign the removal operation with his personal key.

Solution

To solve this problem, we can install a custom solution that allows the program to use the white listing process at the expense of the program when connected to the same Sorana network. Here is one possible attitude:

  • Put a new original program wallet indicating the same address of PDA.

  • Set up a new wallet to pull a public address using the original program with a private key.

  • When the account created in the original program tries to raise funds, it can use a new PDA -shaped address to sign the delete operation.

Code Example

Here is a simple example of how this could be accomplished with the help of the Solana SDK:

`Typedript

Bring {account, program} from@solana/web3.js;

Bring {spltokenrogram} from “./Spl- token-rogram”;

CEMS OriginalRrogram = New program (Spltokenprogram, Original_ process);

Const newwallet = new_wallet, new_wallet_address);

Termination of Async function (account: account) {

// Get a private account PDA -type address

Constvkey = wait account.getprivate ();

// Create a new wallet with a new PDA -type address

Const Newwallet Program = New Program (Spltokenprogram, New_Wallet-Program);

Const newallataddress = Wait newwallet Program.Createaaccount (Privatekey);

// Sign a lifting operation using a new PDA -type address

Const RechlacntraSaction = {

account,

Sum: Splotoken process.Mount,

};

Const Sirestrtransaction = Waiting OrigaliaLrogram.Signransaction

// Send signed action to the network

Wait for the original osensipsipiancedransaction (character);

}

// Use:

Const newwallet = Wait OriginialProgram.newwallet ();

Newwallet Program = Waiting for Newwallet.Createaaccount (NewwalletAddress);

Little Founds.

scalping provider

Leave a Reply

Your email address will not be published. Required fields are marked *