Get program parameters/types for existing program

I would like to ask for the help.

I’m just starting with the Solana contract interacting (I have experiences with EVM) and I’m now struggling with how to call custom foreign programs. Is there any way how to obtain existing programs methods/types in a similar way like in EVM and ABI?

For example, when I would like to transfer token directly with web3.TransactionInstruction() instead of splToken.Token.createTransferInstruction(), is there any way how to get params/types directly from the program on blockchain without having external documentation?

I would like to automatize some contracts but I don’t have docs for them.

I tried connection.getTransaction() to get existing transactions but there are no types and BufferLayout information. I also tried all SolScanners etc but also I didn’t find any info about param names and types.

Is there any way how to do that in Solana? Thanks

1 Like

Hi @ludekvodicka and welcome to the forum and to Solana! :wave:

In Solana, there is not necessarily any specific ABI for Solana programs. Transactions are each made up of the following ingredients:

  • The program ID to send the transaction to
  • A list of Solana accounts ( Which, by the way, aren’t just wallets. In Solana, all data is stored in accounts. )
    • Each account will be specified with an intent to either read from the account or read/write to the account
    • The order the accounts are provided is significant
  • A list of signatures from accounts that are required to authorize the transaction
  • Raw, binary data that will be interpreted by the program that the transaction is sent to

These ingredients are the same for ever transaction regardless of which program you send it to, and it is up to the program how it interprets the accounts, signers, and binary data sent to it.

Each program comes up with it’s own standard for what the data means and there isn’t necessarily a standard you can tell without documentation.

The Anchor framework for writing smart contracts has changed that a little bit by defining schema’s automatically from standardized Rust code and macros.

This means that Anchor programs have programatically described transactions so that bindings to TypeScript ( and probably other languages eventually ) can be automatically generated, and so that Anchor transaction explorers can tell you exactly what a transaction sent to an Anchor program means, instead of it being an opaque lump of bytes and accounts.

Still, this only works for Anchor programs. Not everybody is using Anchor and for many programs you will have to use the project’s SDK or read the source code or documentation to figure out how to send transactions to it.


Hope that helps! Let me know if you have any more questions!

Hello ZIcklag,

thank you for the amazing answer. Your answer exactly confirmed my findings and filled gaps I still had.

So, in case that project is not using Anchor, there is no way how to check the structure of the raw, binary data.

So basically there are only two options. Try to check if the program is based on the Anchor or try to decode binary data based on other transactions.

I also thought about decoding raw data based on the JS on the project website, but I wasn’t successful yet (I’m not JS frontend dev so it’s a little bit challenging for me).

Thanks a lot, I will continue in my research :wink:

(PS: I’m trying to find a way how to automatize StarAtlas mini game)

1 Like

Ah, yeah, Star Atlas is almost surely not going to be using Anchor, at least that’s my guess. Anchor is still under active development and a company like Star Atlas probably isn’t going to want to deal with how it changes and develops unless they were already going to be major contributors to it.

Yeah, it’s not a bad idea, but a lot of sites’ JavaScript can end up pretty cryptic ( pun not intended :upside_down_face: ) because all the JavaScript is compiled, minified, etc. and doesn’t look like reasonable code anymore.

I’ve tried to look at a couple of sites source briefly before and even though I am a JavaScript frontend dev it’s not easy.

That’s probably the best bet. If you play the game manually you can inspect the transactions that it made for you ( or even other people ) on the Solana explorer or Solscan and see what data it submitted.

It’s still going to take some effort to understand the binary data and what’s going on, though.

Glad I could help! Good luck!

Thanks again for the amazing responses.

I already own some small ships and tried to “play” it manually, but these repetitive tasks are killing me ;-). As a programmer, I need to automatize these things.

So I already have these transactions and can test them directly on my wallet, so it’s a little bit easier for me. I will try to replicate the transactions tomorrow based on the solscan and other explorers and I will see how it goes.

Thanks for all.

1 Like