1

I am currently trying to figure out how to decode data from a transaction instruction, but whatever i try it doesn't work.

Example data base58:

2K7nL28PxCW8ejnyCeuMpbWSTLdurgKFpsogNMAfkxaivrGSbx5pnrFeWkZY5EUDZL26WSoMa5kTRAuZiW7s3HifSXN9sWnRp1XnD71rTSxG3GNXxguzpgsXeDQfJx7A5TCPx9t7r5B3KcWsvbxXAivnaY6i82epDwEiCiZ7T2oLg3QsrcZqFjun6QF1

What i should be getting as values in an object:

{
  "mint": {
    "type": "publicKey",
    "data": "6Y6uxUWa2AtijqprubRwx2amJnZkXiK2FM7kJ6E6pump"
  },
  "solAmount": {
    "type": "u64",
    "data": "43099058"
  },
  "tokenAmount": {
    "type": "u64",
    "data": "1219512195121"
  },
  "isBuy": {
    "type": "bool",
    "data": true
  },
  "user": {
    "type": "publicKey",
    "data": "Bzen1deTMBZXh7etJheznKZtDF9KWfgacGSwWV6DPPZ2"
  },
  "timestamp": {
    "type": "i64",
    "data": "1718285628"
  },
  "virtualSolReserves": {
    "type": "u64",
    "data": "33750388325"
  },
  "virtualTokenReserves": {
    "type": "u64",
    "data": "953766803940863"
  }
}

Does anyone have an idea how to decode it?

1 Answer 1

1

Im using this repo: https://github.com/rckprtr/pumpdotfun-sdk

import bs58 from "bs58";
import idl from "../../src/IDL/pump-fun.json";
import {
  BorshCoder,
} from "@coral-xyz/anchor";
import { base64 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

const main = async () => {
  let base58Data =
    "2K7nL28PxCW8ejnyCeuMpbWSTLdurgKFpsogNMAfkxaivrGSbx5pnrFeWkZY5EUDZL26WSoMa5kTRAuZiW7s3HifSXN9sWnRp1XnD71rTSxG3GNXxguzpgsXeDQfJx7A5TCPx9t7r5B3KcWsvbxXAivnaY6i82epDwEiCiZ7T2oLg3QsrcZqFjun6QF1";

  let buffer = Buffer.from(bs58.decode(base58Data));
  //remove first 8 bytes for the event cpi
  buffer = buffer.slice(8);
  
  let coder = new BorshCoder(idl as any);
  let args = coder.events.decode(base64.encode(buffer));
  console.log(args);
};

main();

Results:

{
  data: {
    mint: PublicKey [PublicKey(6Y6uxUWa2AtijqprubRwx2amJnZkXiK2FM7kJ6E6pump)] {
      _bn: <BN: 52422028108045a3dfbc44fb5428a6cee7ea2f55bdd87164929a93663d3145ff>
    },
    solAmount: <BN: 291a3b2>,
    tokenAmount: <BN: 11bf0975831>,
    isBuy: true,
    user: PublicKey [PublicKey(Bzen1deTMBZXh7etJheznKZtDF9KWfgacGSwWV6DPPZ2)] {
      _bn: <BN: a359b05b86c4036aafbfaa3bda65369edf96fd8630852ee5d38e7fe79199b429>
    },
    timestamp: <BN: 666af53c>,
    virtualSolReserves: <BN: 7dbae0e65>,
    virtualTokenReserves: <BN: 36372238c25ff>,
    realSolReserves: <BN: df8a6265>,
    realTokenReserves: <BN: 264e0d7798dff>
  },
  name: 'TradeEvent'
}
1
  • 1
    life saver lol thank you Commented Jun 13 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.