Shouldn't this work to get the public key according to the documentation? I tried the below code and get an error TypeError: wallet.publicKey is not a function. https://solana-labs.github.io/solana-web3.js/classes/Keypair.html

let wallet = solana_web3.Keypair.generate();

How do I get a copy of this https://solana-labs.github.io/solana-web3.js/classes/PublicKey.html from the generated wallet?

2 Answers 2


i believe that you just need to replace wallet.publicKey() with wallet.publicKey because you are reading a property, not calling a method

import { PublicKey, Keypair } from "@solana/web3.js";

const wallet = Keypair.generate();
const pubKey=wallet.publicKey

as your PublicKey docs link, PublicKey is a class and its constructor is

new PublicKey(value: PublicKeyInitData): PublicKey

to create a PublicKey instance

// I generated the pubKey above
const publicKeyInstance = new PublicKey(pubKey);

Now you should be accessing all the methods in the PublicKey docs

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.