Last active
August 9, 2022 18:48
-
-
Save mertimus/ac8f2ac153042b243d255566bcabf95f to your computer and use it in GitHub Desktop.
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
import { serialize, deserializeUnchecked } from 'borsh'; | |
import { Connection, PublicKey, Struct } from '@solana/web3.js'; | |
const Base58 = require("base-58") | |
import * as beet from '@metaplex-foundation/beet'; | |
const url = "rpc url"; | |
const solanaConnection = new Connection(url,'confirmed'); | |
// metaplex source: https://github.com/metaplex-foundation/metaplex-program-library/blob/master/auction-house/js/src/generated/instructions/executeSale.ts#L17 | |
class Primitive { | |
tradeStateBump: number; | |
freeTradeStateBump: number; | |
programAsSignerBump: number; | |
buyerPrice: beet.bignum; | |
tokenSize: beet.bignum; | |
constructor(args: { | |
tradeStateBump: number; | |
freeTradeStateBump: number; | |
programAsSignerBump: number; | |
buyerPrice: beet.bignum; | |
tokenSize: beet.bignum; | |
}) { | |
this.tradeStateBump = args.tradeStateBump; | |
this.freeTradeStateBump = args.freeTradeStateBump | |
this.programAsSignerBump = args.programAsSignerBump | |
this.buyerPrice = args.buyerPrice | |
this.tokenSize = args.tokenSize | |
} | |
} | |
const value = new Primitive({ | |
tradeStateBump: 255, | |
freeTradeStateBump: 254, | |
programAsSignerBump: 255, | |
buyerPrice: 35000000000, | |
tokenSize: 1, | |
}) | |
const schema = new Map([[Primitive,{ | |
kind: 'struct', | |
fields: [ | |
['instructionDiscriminator', ['u8', 8]], | |
['tradeStateBump', 'u8'], | |
['freeTradeStateBump', 'u8'], | |
['programAsSignerBump', 'u8'], | |
['buyerPrice', 'u64'], | |
['tokenSize', 'u64'], | |
] | |
}]]); | |
const parser = async () => { | |
const txn = await solanaConnection.getTransaction("4Jsmb6WeDzhLAaRF494CfbFLh6Vg2TCSfHKMWN18ueyaVzdQjf69GX4SDDdGFowey8g81DgFv7inQrTEyJiG49op"); | |
const test = Buffer.from(Base58.decode(txn?.transaction.message.instructions[0].data)) | |
const data = deserializeUnchecked(schema, Primitive, test) | |
console.log("price:", data.buyerPrice.toString()) | |
} | |
parser() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment