Blockhash
A recent blockhash, for transactions you build yourself.
Most transactions come ready-made from /api/sol/trade-local. For the ones you build yourself (moving SOL between your wallets, closing empty token accounts) you need a recent blockhash: get it here, build and sign the transaction, then send it with /api/sol/send. No RPC of your own needed.
GEThttps://api.trenchytools.lol/api/sol/blockhash
import { SystemProgram, TransactionMessage, VersionedTransaction } from '@solana/web3.js'
const { blockhash } = await (await fetch(`${BASE}/api/sol/blockhash?api-key=${API_KEY}`)).json()
const tx = new VersionedTransaction(new TransactionMessage({
payerKey: from.publicKey,
recentBlockhash: blockhash,
instructions: [SystemProgram.transfer({ fromPubkey: from.publicKey, toPubkey: to, lamports: 10_000_000 })],
}).compileToV0Message())
tx.sign([from])
await fetch(`${BASE}/api/sol/send?api-key=${API_KEY}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ transaction: Buffer.from(tx.serialize()).toString('base64') }),
})
Response
{ "blockhash": "5tt5pLPN…", "lastValidBlockHeight": 438211042 }