I'm used to the Solana web3.js library, but have recently started using Anchor.

I can see Anchor's TS client connects to my local cluster when I run my transaction, but how do I get the normal web3.js connection object from Anchor?

2 Answers 2


You can load the provider with

const provider = getProvider() as AnchorProvider;

and now you can access provider.connection.

You may also be interested in the wallet const wallet = provider.wallet as Wallet;

  • Thanks for answering! This seems like the same answer - provider.connection - as the older answer above though.
    – mikemaccana
    Mar 14 at 19:19

Answering my own question to help others

The connection can be accessed through

const connection = program.provider.connection;

I can't find any information about Anchor Providers on the Anchor website but I did find a doc describing Anchor Providers at the Anchor GitHub.

  • Downvoter - is there anything I can do to improve my answer?
    – mikemaccana
    Mar 15 at 15:13

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.