import { Connection, Transaction, SystemProgram, PublicKey } from '@solana/web3.js';
const tx = new Transaction().add(
SystemProgram.transfer({
fromPubkey: new PublicKey(receiverWallet),
toPubkey: new PublicKey(destWallet),
lamports: 1_000_000,
})
);
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
tx.feePayer = new PublicKey(receiverWallet);
const serialized = tx.serialize({ requireAllSignatures: false }).toString('base64');
const res = await fetch(`https://api.astronpay.co/api/v1/receivers/${receiverId}/wallet/sign-and-send-transaction`, {
method: 'POST',
headers: {
'x-api-key': apiKey,
'x-api-secret': apiSecret,
'Content-Type': 'application/json',
},
body: JSON.stringify({ transaction: serialized }),
});
const { hash } = await res.json();