Untitled
plain_text
a month ago
2.4 kB
1
Indexable
Never
function bufferToHex(buffer: Uint8Array): string { return Buffer.from(buffer).toString("hex"); } function hexToBuffer(hex: string): Uint8Array { return new Uint8Array(Buffer.from(hex, "hex")); } /// Modify MSG and SIGNATURE const MSG = "f07e2347a53d14549a5908a3fe151bbbe68888e6f6d980154f666754721c1d9302503fa0dddce53f79a2d5640000000054dd182b468df06000d8e8e85722520976a2f59e7e48e2c0f690bb085778db8b00e1f50500000000"; const SIGNATURE = "208047d6b8f545fc42e713a0ecc0a29009a8fc015fbfb89b075a319d4a232177f8b9475a34df2211367c3092de41f5f3693a5a9150b951d6d500be50b5f6110b"; /// ==== const SIGNER = "8gp98u7TzYEjPc71euKwuCCbrY77srZY3u3ct3aEJRcJ"; const [config, _configBump] = web3.PublicKey.findProgramAddressSync( [Buffer.from(anchor.utils.bytes.utf8.encode("config"))], pg.PROGRAM_ID ); const [solBank, _solBankBump] = web3.PublicKey.findProgramAddressSync( [Buffer.from(anchor.utils.bytes.utf8.encode("sol_bank"))], pg.PROGRAM_ID ); let [nonce, _nonceBump] = await web3.PublicKey.findProgramAddress( [ Buffer.from(anchor.utils.bytes.utf8.encode("nonce")), Buffer.from(Array.from(new Uint8Array(hexToBuffer(MSG)).slice(32, 40))), ], pg.program.programId ); let tx = new anchor.web3.Transaction() .add( // Ed25519 instruction anchor.web3.Ed25519Program.createInstructionWithPublicKey({ publicKey: new web3.PublicKey(SIGNER).toBytes(), message: new Uint8Array(hexToBuffer(MSG)), signature: new Uint8Array(hexToBuffer(SIGNATURE)), }) ) .add( // Our instruction await pg.program.methods .claimMetatx( Buffer.from(hexToBuffer(MSG)), Array.from(new Uint8Array(hexToBuffer(SIGNATURE))) ) .accounts({ solBank: solBank, user: pg.wallet.publicKey, ixSysvar: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY, systemProgram: anchor.web3.SystemProgram.programId, config: config, nonce: nonce, }) .instruction() ); tx.recentBlockhash = (await pg.connection.getLatestBlockhash()).blockhash; tx.feePayer = pg.wallet.publicKey; const signedTx = await pg.wallet.signTransaction(tx); try { const txId = await pg.connection.sendRawTransaction(signedTx.serialize()); await pg.connection.confirmTransaction(txId); console.log("Tx Id: " + `https://solscan.io/tx/${txId}?cluster=devnet`); } catch (err) { console.log(err); }