Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Impossible to use solana connection in vanilla JS #3553

Closed
beeb opened this issue Dec 30, 2024 · 17 comments
Closed

[bug] Impossible to use solana connection in vanilla JS #3553

beeb opened this issue Dec 30, 2024 · 17 comments
Labels
bug Something isn't working

Comments

@beeb
Copy link

beeb commented Dec 30, 2024

Link to minimal reproducible example

https://stackblitz.com/edit/vitejs-vite-i19qspur?file=src%2Fmain.js

Summary

In vanilla JS, it is currently impossible to retrieve the solana Connection object from @reown/appkit-adapter-solana.

The vue and react exports specify a useAppKitConnection hook to retrieve that connection, but it's unavailable in vanilla JS.

Even the SolStoreUtil cannot be imported from @reown/appkit-adapter-solana because it's only exported as a type here:

export type * from './utils/SolanaStoreUtil.js'

List of related npm package versions

@reown/appkit-adapter-solana v1.6.2

Node.js Version

v22

Package Manager

pnpm 9.15.1

@beeb beeb added bug Something isn't working needs review labels Dec 30, 2024
Copy link

linear bot commented Dec 30, 2024

@reown-com reown-com deleted a comment Dec 30, 2024
@rtomas
Copy link
Contributor

rtomas commented Dec 30, 2024

Thanks for reporting the issue ... we are working to solve it as soon as possible.

@arein
Copy link
Contributor

arein commented Jan 2, 2025

Thx for reporting @beeb - curious - what are you building?

@beeb
Copy link
Author

beeb commented Jan 2, 2025

@arein just trying to find the best way to integrate with Svelte. No particular project in mind.

@ethan-tqa
Copy link

Yep, I have also filed a bug report for the doc here: reown-com/reown-docs#230

@souvikmishra
Copy link

@beeb hey! I had faced a similar issue but with ethers, maybe this would be of help #3468

@beeb
Copy link
Author

beeb commented Jan 15, 2025

@souvikmishra thanks for the link, but the proposed solution to subscribe doesn't work here, because there is no subscribe method for the solana connection.

@souvikmishra
Copy link

Ah... I thought it might be helpful 🙆‍♂️ anyways if I come across something else I'll be sure to drop it here.

Copy link

Thank you for raising this - team will look into it!

@magiziz
Copy link
Contributor

magiziz commented Jan 20, 2025

@beeb Why do you need solana connection directly from appkit ? Can you do something like this ?

const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed')

@beeb
Copy link
Author

beeb commented Jan 20, 2025

@magiziz it's available to react and vue users, so why not vanilla (i.e. svelte and all the other frameworks)?

@beeb
Copy link
Author

beeb commented Jan 20, 2025

Can you do something like this ?

I would rather not. The advantage of using the same connection that the client is using is you are sure you get the same data because it uses the same RPC. Likewise, when the network changes, the client automatically updates the connection which would then make sure that the network/chain is the same for all of the application. Doing it otherwise is at best a hack, at worst error-prone.

@magiziz
Copy link
Contributor

magiziz commented Jan 21, 2025

@beeb we're choosing the first available RPC provider that's available in the networks. Here is the code if you're curious.

For now i think the best solution is to do this.

import { Connection } from '@solana/web3.js'

import { SolHelpersUtil } from '@reown/appkit-adapter-solana'
import { solana } from '@reown/appkit/networks'

const rpcUrl = SolHelpersUtil.detectRpcUrl(solana, 'YOUR_PROJECT_ID') as string

if (!rpcUrl) {
  throw new Error('No RPC URL found')
}

const connection = new Connection(rpcUrl, 'confirmed')

If we were to expose this in vanilla js it would require some refactoring work and this hasn't been requested from a lot of people. Let me know if the solution above works for now.

@beeb
Copy link
Author

beeb commented Jan 21, 2025

@magiziz the easiest "fix" that would not require refactoring would be to export the SolStoreUtil singleton no? At the moment it's only exported as a type.

@magiziz
Copy link
Contributor

magiziz commented Jan 21, 2025

@beeb I think if we were to expose SolStoreUtil it wouldn't be the nicest approach, instead i think we should expose this from createAppKit, but for that to happen we would need to do some refactoring. Can you use the approach i gave above and see if that works ? It should be the same

@beeb
Copy link
Author

beeb commented Jan 21, 2025

Well I would need to also watch for chain changes in your proposed approach. But yeah I guess it would be a kind of workaround. I strongly encourage you to fix this at some point if the ambition is to become the de facto standard for solana dApps.

@magiziz
Copy link
Contributor

magiziz commented Jan 21, 2025

@beeb yes we'll take a look at this, but as a workaround you can use the approach above. Please re-open this issue if you're still stuck 🙏

@magiziz magiziz closed this as completed Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants