0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Parse solana raw transaction instruction data

Last updated at Posted at 2024-06-11
import bs58 from "bs58";
import * as borsh from "borsh";
import { Schema } from "borsh";

const schema = {
  struct: {
    discriminator: "u64",
    buyerPrice: "u64",
    tokenSize: "u64",
    buyerStateExpiry: "i64",
    buyerCreatorRoyaltyBp: "u16",
    extraArgs: {
      array: {
        type: "u8",
      },
    },
  },
};

const data = "UEVYJrzmev2UQ1cVQ8mBufZjnj8LT83s1ukeQvg1kERm5M7F3oaX";
const decoded = borsh.deserialize(schema, Buffer.from(bs58.decode(data)));
console.log(decoded);

//////
const schema2 = {
  struct: {
    discriminator: "u8",
  },
};
const data2 = "84eT";
const decoded2 = borsh.deserialize(schema2, Buffer.from(bs58.decode(data2)));
console.log(decoded2);

//////
const schema3 = schema2;
const data3 = "P";
let bytes3 = bs58.decode(data3);
console.log(Buffer.from(bytes3).toString("hex"));

const decoded3 = borsh.deserialize(schema3, Buffer.from(bs58.decode(data3)));
console.log(decoded3);

//////
const schema4 = {
  struct: {
    discriminator: "u8",
    authority: {
      array: {
        // Pubkey [u8; 32]);
        type: "u8",
        len: 32,
      },
    },
  },
};

const data4 = "6MnUrhc3pqaYAVEir8UMwNSBDdUmGJb8GxTkm1JzXQQev";
let bytes4 = bs58.decode(data4);
console.log(Buffer.from(bytes4).toString("hex"));

const decoded4 = borsh.deserialize(schema4, Buffer.from(bs58.decode(data4)));
console.log(decoded4);

const obj = JSON.parse(JSON.stringify(decoded4));
const uint8Array = new Uint8Array(obj.authority);
const addr = bs58.encode(uint8Array);
console.log(addr);

discern Jupiter v6 inx: SharedAccountsRoute

from hashlib import sha256

def camel_to_snake(text):
    import re
    str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
    return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower()

ix_name = "SharedAccountsRoute"

stuff = f"global:{camel_to_snake(ix_name)}"
encode = sha256(stuff.encode()).digest()[:8]
print(encode.hex())


Ref:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?