Created
June 5, 2024 17:47
-
-
Save wphan/9464c2480fb8460f15c6d5d52d7ebd4a to your computer and use it in GitHub Desktop.
Simulate a transaction from base58 blob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dependencies: | |
// "@solana/web3.js": "1.91.8", | |
// "@coral-xyz/anchor": "^0.29.0", | |
import * as bs58 from '@coral-xyz/anchor/dist/cjs/utils/bytes/bs58' | |
import { | |
Connection, | |
VersionedTransaction, | |
} from "@solana/web3.js"; | |
const main = async () => { | |
const connection = new Connection("https://api.mainnet-beta.solana.com"); | |
const base58Tx = "4J29eFKUpnWMuktTAFQervdYSa83QKjdTQYw7QpwnnUuaHYCbzybabQSTua2MaxmHzS5ie3j9pMVQMT3fP4USziXyRsGSjiBV5yoTiX2BBcaLDMdGBB1xt7u1ZK2VWUKYjrymv48jEBnija76N1k1peafpEs5azTgtgnDg1Y4u75vugHdAaixV2uRghLkisk7FopMShyyzqHzyPk2yzuLWJ7PGrFXGY2w5SmSxWRs2fbpcftekMv2RnpJKFXp2DPT2gRTBSLLzV3bBXuMcEVWX3nJGPDgb8DULtrcu64qKiHbPHVH4bvopN2WXUoqavZA2wViaQ47Ldn7FWzbY1H7W9d2v4vhd8azitMSymoQZ1tbpt62XJb9RZhPi7gpS4WnJcM659b7N8nJzjAJdtprb1az9PLSTTV6rq88RDsRDJzgSyfxu6Fu9ukrbENtNsC8cXJwskBeBpUviczrh8Yg7TEoyt7yF6PH5k6FDSHR6ojxidTMvFYQEJitQ"; | |
const tx = VersionedTransaction.deserialize(bs58.decode(base58Tx)); | |
tx.message.recentBlockhash = (await connection.getLatestBlockhash('finalized')).blockhash; | |
console.log(await connection.simulateTransaction(tx, {sigVerify: false})); | |
} | |
main().catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment