I did a lot of research on this subject but could not reach a conclusion. What I want to do is this; I list and display the NFTs in my user's wallet using a specific collectionKey (my own collectionKey). From here, the user will select an NFT and perform the freezing process. This may or may not be for a certain period of time. The user will select and confirm the freezing process and I will give him a special reward (like points) from my system. How do I do this? How can I find a library/framework code sample or how to do it for React?
-
Hey there, in order to achieve this goal you would need to freeze his token account using the the FreezeAccount instruction. To thaw the token account you will need to use the ThawAccount instruction.– beliveN DAOist.devCommented Feb 22 at 16:15
-
Yes, I have information about this. However, when I examined the developer documentation, I could not find anything. You see, I need help with the code. Thanks– exortekCommented Feb 22 at 21:27
-
Freeze Account Instruction github.com/solana-labs/solana-program-library/blob/master/token/… and Thaw Account Instruction github.com/solana-labs/solana-program-library/blob/master/token/… You need to import this 2 instructions.– beliveN DAOist.devCommented Feb 23 at 1:10
Add a comment
|
2 Answers
in order to freeze the token account and thaw the token account you need to import this instructions createFreezeAccountInstruction and createThawAccountInstruction from @solana/spl-token
createFreezeAccountInstruction(
tokenAccount,//Account to freeze
mint,//Mint account
payer.publicKey//Mint freeze authority
)
createThawAccountInstruction(
tokenAccount,//Account to freeze
mint,//Mint account
payer.publicKey//Mint freeze authority
)
Example:
(async () => {
const tokenAccount = new PublicKey('token id');
try {
let tx = new Transaction().add(
createFreezeAccountInstruction(
tokenAccount,
mint,
payer.publicKey
)
)
//sign tx
let txhash = await sendAndConfirmTransaction(connection, tx, [keypair]);
console.log(txhash)
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();
-
I think I wrote the code. However, I get the "Owner does not match" error. However, all the information I have given here is correct. Could there be another reason why I'm experiencing this?– exortekCommented Feb 23 at 15:27
-
MINT: EQTXXd12kB4QjNupxAJg9fhYVE2wMM9Rvc9EgPopsbN TOKEN_ACCOUNT: 9iYcdXhFh5jTj4PKZpWXhixbMNfZkfLJm9XWZso2jaXb OWNER: 47F47sC2NVyoMGYubT2VkMay3FSJaFbhnYNXew4iRWLu– exortekCommented Feb 23 at 15:27
-
These come dynamically. I use provider for Phantom wallet and Solana. The error I get in Phantom is as above. "Owner does not match"– exortekCommented Feb 23 at 15:29
-
From what i checked the mint is : EQTXXd12kB4QjNupxAJg9fhYVE2wMM9Rvc9EgPopsbN token acc: 9iYcdXhFh5jTj4PKZpWXhixbMNfZkfLJm9XWZso2jaXb Mint/freeze Auth: 47mvLdPJe5EEXGtksYw6fNErP5GzogjSq1u6LJCKe9yP Commented Feb 23 at 17:33
-
What's wrong?
'use client';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { PublicKey, Transaction } from '@solana/web3.js';
import { createFreezeAccountInstruction } from '@solana/spl-token';
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui';
function Page() {
const wallet = useWallet();
const { connection } = useConnection();
const freezeUserWalletNFT = async () => {
const tx = new Transaction();
const account = new PublicKey('9iYcdXhFh5jTj4PKZpWXhixbMNfZkfLJm9XWZso2jaXb');
const mint = new PublicKey('EQTXXd12kB4QjNupxAJg9fhYVE2wMM9Rvc9EgPopsbN');
const payer = wallet.publicKey;
const authority = new PublicKey('47mvLdPJe5EEXGtksYw6fNErP5GzogjSq1u6LJCKe9yP');
tx.add(createFreezeAccountInstruction(account, mint, authority));
tx.recentBlockhash = (await connection.getLatestBlockhash('max')).blockhash;
tx.feePayer = payer;
const signature = await wallet.signTransaction(tx);
const result = await connection.sendRawTransaction(signature.serialize());
console.log('Transaction result:', result);
};
return (
<div className='w-full flex flex-col items-center justify-center py-12 gap-12'>
<button onClick={freezeUserWalletNFT}>Freeze Wallet NFT</button>
<WalletMultiButton>{wallet.connected ? wallet.publicKey?.toBase58() : <button onClick={wallet.connect}>Connect Wallet</button>}</WalletMultiButton>
</div>
);
}
export default Page;