2

I am trying to send a transaction to my program through rust client. But i am running into an issue and i would like to see the logs so that i can trace it.

I am using the anchor rust client and following the example below.

https://github.com/coral-xyz/anchor/blob/master/client/example/src/blocking.rs#L182

Running the test, i get the following error.

Error: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction [2 log messages]

Caused by:
    0: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction [2 log messages]
    1: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction [2 log messages]
test tests::test_deliver ... FAILED

How can i view the log messages?

2 Answers 2

3

If you boot the local validator yourself in another terminal using solana-test-validator, then in another terminal subscribe to the logs using solana logs -ul, then you can run anchor test --skip-local-validator and see the full transaction log.

4
  • Thanks for the answer but the above method didnt return the logs of the failed transaction. Before doing a tx to my program, i do an airdrop which is successful. So i can only see the airdrop tx as the last transaction in the logs and there is no logs about the tx to my program which is what i need. Commented Oct 11, 2023 at 16:11
  • Ohh yeah try it with skipPreflight: true
    – Joe C
    Commented Oct 11, 2023 at 16:14
  • Where should i add the above? Commented Oct 11, 2023 at 16:42
  • 1
    You can use this alternative send method, which takes RpcSendTransactionConfig and has the field in it
    – Joe C
    Commented Oct 12, 2023 at 13:52
0

If you want to get the logs from JS/TS, for example you need to so an assertion in your tests, you can use getLogs() from the Solana helpers module.

Since you're using Anchor, get the web3.js connection object from your Anchor provider:

const connection = program.provider.connection;

Then just:

const logs = await getLogs(connection, tx);

Logs is an array of strings.

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.