const { web3, AnchorProvider, Wallet, Program, BN } = require('@coral-xyz/anchor');
const { TOKEN_PROGRAM_ID } = require('@solana/spl-token');
const privateKey = Buffer.from([
208, 112, ....
]);
const authority = web3.Keypair.fromSecretKey(privateKey);
const connection = new web3.Connection(web3.clusterApiUrl('devnet'));
const provider = new AnchorProvider(connection, new Wallet(authority), {
preflightCommitment: 'processed',
});
const programID = '3Un5jbAXNo7Rve5pXm7qE2ct8Bi8HdP41dP8o3XYDBUG';
async function init() {
const idl = await Program.fetchIdl(programID, provider);
const program = new Program(idl, programID, provider);
const store = web3.Keypair.generate();
console.log({
pk: store.publicKey.toString(),
sk: store.secretKey.toString(),
});
const [vault, bump] = web3.PublicKey.findProgramAddressSync(
[Buffer.from('vault'), store.publicKey.toBuffer()],
program.programId
);
console.log({ vault, bump });
const tx = await program.methods
.initialStore()
.accounts({
signer: authority.publicKey,
store: store.publicKey,
storeVault: vault,
})
.signers([authority, store])
.rpc();
console.log({ tx });
}
async function wd() {
const idl = await Program.fetchIdl(programID, provider);
const program = new Program(idl, programID, provider);
const store = new web3.PublicKey('DaRFNFR1ZRT6y6P3QDgwtf36tGV8qgK8sqT7CfvPLb9G');
const [vault, bump] = web3.PublicKey.findProgramAddressSync(
[Buffer.from('vault'), store.toBuffer()],
program.programId
);
console.log({ vault, bump });
const tx = await program.methods
.withdraw(new BN(bump))
.accounts({
store: store,
storeVault: vault,
destination: authority.publicKey,
systemProgram: web3.SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.rpc();
console.log({ tx });
}
wd();