I am trying to starting code to name my solana token i was following but he was sucessful but i am not. I am using ubuntu and I am coding in vscode and running the program like ts-node main.ts. How to name your solana token Here is my code
import * as mpl from "@metaplex-foundation/mpl-token-metadata"
import * as web3 from "@solana/web3.js"
export function loadWalletKey(keypairFile:string): web3.Keypair
{
const fs = require("fs");
const loaded = web3.Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
);
return loaded;
}
async function main(){
console.log("starting");
const myKeypair = loadWalletKey("BnAkGcoFJ9J7h3ZK8k3ZxbYQfa5RfEKmhz6UfxdwLR5d.json");
console.log(myKeypair.publicKey);
const accounts = {
metadata:web3.PublicKey,
mint:web3.PublicKey,
mintAuthority:web3.PublicKey,
payer:web3.PublicKey,
updateAuthority:web3.PublicKey,
}
//mpl.createCreateMetadataAccountInstruction(accounts,args);
}
main();
And here is the error i am getting.
/home/cube/typescripts/node_modules/@solana/web3.js/lib/index.cjs.js:644
keyMeta.isSigner ||= accountMeta.isSigner;
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/cube/typescripts/main.ts:3:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
I am expecting it to work the same without errors and print the public key as of video as of 12:00 to 12:25 i think in video.
Be sure to update to at least Node version 16. The newer web3.js library uses the ||=
syntax which is unsupported for versions before 16.