1

Is there a way how to (programmatically) reserve an amount on wallet A (not owned by me, but the owner is willing to give a permission for this transaction) (preferably if it couldn't be used for anything else) that by a certain time (for example in 2 day) might or might not transferred reserved tokens into another wallet B (depending on external factors - e.g.: party B did something for party A)

Is this somehow possible, or are at least some parts of this doable? Is there some library that could help with that?

1 Answer 1

1

Yes, this is known to as Authority Delegation

"Account owners may delegate authority over some or all of their token balance using the Approve instruction. Delegated authorities may transfer or burn up to the amount they've been delegated. Authority delegation may be revoked by the Account's owner via the Revoke instruction."

You can use the approveChecked function from the @solana/spl-token library to implement this:

let txhash = await approveChecked(
      connection, // connection
      feePayer, // fee payer
      mintPubkey, // mint
      tokenAccountPubkey, // token account
      randomGuy.publicKey, // delegate
      alice, // owner of token account
      1e8, // amount, if your deciamls is 8, 10^8 for 1 token
      8 // decimals
);
console.log(`txhash: ${txhash}`);

You will have the authority to transfer or burn the tokens until the authority is revoked.

You can find the full example in the solana cookbook

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.