ts, examples: Fix web3.js usage

This commit is contained in:
armaniferrante 2021-03-30 20:19:05 -07:00
parent 46a9ff9dab
commit 6576e0d7ff
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
4 changed files with 14 additions and 7 deletions

View File

@ -72,6 +72,12 @@ describe("token", () => {
const serumCmn = require("@project-serum/common"); const serumCmn = require("@project-serum/common");
const TokenInstructions = require("@project-serum/serum").TokenInstructions; const TokenInstructions = require("@project-serum/serum").TokenInstructions;
// TODO: remove this constant once @project-serum/serum uses the same version
// of @solana/web3.js as anchor (or switch packages).
const TOKEN_PROGRAM_ID = new anchor.web3.PublicKey(
TokenInstructions.TOKEN_PROGRAM_ID.toString()
);
async function getTokenAccount(provider, addr) { async function getTokenAccount(provider, addr) {
return await serumCmn.getTokenAccount(provider, addr); return await serumCmn.getTokenAccount(provider, addr);
} }
@ -102,7 +108,7 @@ async function createMintInstructions(provider, authority, mint) {
newAccountPubkey: mint, newAccountPubkey: mint,
space: 82, space: 82,
lamports: await provider.connection.getMinimumBalanceForRentExemption(82), lamports: await provider.connection.getMinimumBalanceForRentExemption(82),
programId: TokenInstructions.TOKEN_PROGRAM_ID, programId: TOKEN_PROGRAM_ID,
}), }),
TokenInstructions.initializeMint({ TokenInstructions.initializeMint({
mint, mint,
@ -139,7 +145,7 @@ async function createTokenAccountInstrs(
newAccountPubkey, newAccountPubkey,
space: 165, space: 165,
lamports, lamports,
programId: TokenInstructions.TOKEN_PROGRAM_ID, programId: TOKEN_PROGRAM_ID,
}), }),
TokenInstructions.initializeAccount({ TokenInstructions.initializeAccount({
account: newAccountPubkey, account: newAccountPubkey,

View File

@ -24,7 +24,7 @@
}, },
"dependencies": { "dependencies": {
"@project-serum/borsh": "^0.1.0", "@project-serum/borsh": "^0.1.0",
"@solana/web3.js": "^1.1.0", "@solana/web3.js": "^1.2.0",
"@types/bn.js": "^4.11.6", "@types/bn.js": "^4.11.6",
"@types/bs58": "^4.0.1", "@types/bs58": "^4.0.1",
"@types/crypto-hash": "^1.1.2", "@types/crypto-hash": "^1.1.2",

View File

@ -15,6 +15,7 @@ async function getMultipleAccounts(
Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }> Array<null | { publicKey: PublicKey; account: AccountInfo<Buffer> }>
> { > {
const args = [publicKeys.map((k) => k.toBase58()), { commitment: "recent" }]; const args = [publicKeys.map((k) => k.toBase58()), { commitment: "recent" }];
// @ts-ignore
const res = await connection._rpcRequest("getMultipleAccounts", args); const res = await connection._rpcRequest("getMultipleAccounts", args);
if (res.error) { if (res.error) {
throw new Error( throw new Error(

View File

@ -676,10 +676,10 @@
dependencies: dependencies:
"@sinonjs/commons" "^1.7.0" "@sinonjs/commons" "^1.7.0"
"@solana/web3.js@^1.1.0": "@solana/web3.js@^1.2.0":
version "1.1.0" version "1.2.3"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.1.0.tgz#b31815c9fa7cabeefe8175034bfe300b9d4011e7" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.2.3.tgz#8d4c1f70b8c208c721eeca03c9624d3638ba3d7f"
integrity sha512-n8O5wvoogrwQJWe9rQml/QlN+lQu9VaBGueeSR/9oyefktzchZS9ar1hsatybCvqNSRQCnmTme9zQwY1kJkMGw== integrity sha512-aDsFJhefIiKh9kb3xeWcX5rsAPdUqJtz61F9tplfp//mYVpzKZeWYZSUKB39PXo7c5ZrxVeBx7am4J7NB10Pcg==
dependencies: dependencies:
"@babel/runtime" "^7.12.5" "@babel/runtime" "^7.12.5"
bn.js "^5.0.0" bn.js "^5.0.0"