-
Notifications
You must be signed in to change notification settings - Fork 857
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
Deno Support for Web3.js API #1120
Comments
I just discovered that importing import * as solana from "https://esm.sh/@solana/web3.js@1.31.0/lib/index.browser.esm.js"; |
I'm discovering that the above workaround doesn't work well because as soon as I need another library such as the I can't find a way to get the Orca SDK and Solana web3.js to work in Deno. I'll have to see how other projects manage to support Deno and NodeJS at the same time. |
@zicklag have you managed to find a solution? |
@azerpas no, I haven't figured it out yet. I think there's got to be a way to organize the hosting of the Solana web3.js builds so that esm.js or another option such as https://www.skypack.dev/ would be able to load it, but I haven't had time to look into exactly what's necessary. |
I've finally managed to make it work with import * as solana from "https://dev.jspm.io/@solana/web3.js";
import * as anchor from "https://esm.sh/@project-serum/anchor@0.17.0?dev&no-check" |
Oh sweet! Good find. I'll have to try that out. I haven't tried |
@azerpas were you able to get types working? |
Sadly no, switched to JS |
I would really love to see Deno getting supported! +1 |
gravedigging this to report that Deno support is somewhat functional with for reference, here is a working submission of a transaction: // adapted from `https://stackoverflow.com/a/68167035`
import {
Connection,
Keypair,
Transaction,
clusterApiUrl,
SystemProgram,
LAMPORTS_PER_SOL,
} from "https://esm.sh/v111/@solana/web3.js@1.73.3/deno/web3.js";
const DEMO_FROM_SECRET_KEY = new Uint8Array([
37, 21, 197, 185, 105, 201, 212, 148, 164, 108, 251, 159, 174, 252, 43, 246,
225, 156, 38, 203, 99, 42, 244, 73, 252, 143, 34, 239, 15, 222, 217, 91, 132,
167, 105, 60, 17, 211, 120, 243, 197, 99, 113, 34, 76, 127, 190, 18, 91, 246,
121, 93, 189, 55, 165, 129, 196, 104, 25, 157, 209, 168, 165, 149,
]);
export async function TestSolTransfer() {
// Connect to cluster
const connection = new Connection(clusterApiUrl("devnet"));
// Construct a `Keypair` from secret key
const from = Keypair.fromSecretKey(DEMO_FROM_SECRET_KEY);
// Generate a new random public key
const to = Keypair.generate();
// Add transfer instruction to transaction
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: to.publicKey,
lamports: LAMPORTS_PER_SOL / 100,
})
);
// Sign transaction, broadcast, and confirm
const signature = await connection.sendTransaction(transaction, [from]);
console.log("SIGNATURE", signature);
console.log("SUCCESS");
} |
Seems to work to me! You have to use the // index.ts
import { Connection } from 'npm:@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com');
const blockHeight = await connection.getBlockHeight();
console.log('blockHeight', blockHeight); …then deno index.ts 🎉 |
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
Problem
I would like to use Deno to interface with the Solana chain, but the
web3.js
API cannot import properly into deno.Proposed Solution
I'm not 100% sure the best strategy for supporting Deno yet, but I might be investigating and I'll post here if I find any promising strategies.
I have tried solutions such as
esm.sh
and other Deno ESM module proxies to NPM, but none of them have been successful.It may actually be easier to port the browser build to Deno, because Deno implements many of the browser APIs such a
fetch()
, etc.The text was updated successfully, but these errors were encountered: