Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

501
Vistas
TypeError: y.pubkey.toBase58 is not a function

I am trying to send 1 solana

I have this code

But it throws an error: Uncaught (in promise) TypeError: y.pubkey.toBase58 is not a function at transaction.ts:264:33

Help solve this error

async function connectWallet() {

    let provider = null

    if ("solana" in window) {
        provider = window.solana;
        if (provider.isPhantom) {
            console.log('provider', provider)
        }
    } else {
        window.open("https://phantom.app/", "_blank");
    }

    publicKey = null

    if (provider != null) {
        try {
            const resp = await window.solana.connect();
            publicKey = resp.publicKey.toString();

        } catch (err) {
            // { code: 4001, message: 'User rejected the request.' }
            console.log(err)
        }
    }

    if (publicKey != null) {
        const message = `Sign below to authenticate`;
        const encodedMessage = new TextEncoder().encode(message);
        const signedMessage = await window.solana.request({
            method: "signMessage",
            params: {
                message: encodedMessage,
                display: "utf-8",
            },
        });

        var recieverWallet = new solanaWeb3.PublicKey("4iSD5Q6AnyhRHu6Uz4u1KAzXh3TwNwwQshEGhZbEXUTw");


        const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl("mainnet-beta"));

        var transaction = new solanaWeb3.Transaction().add(
            solanaWeb3.SystemProgram.transfer({
              fromPubkey: publicKey,
              toPubkey: recieverWallet,
              lamports: solanaWeb3.LAMPORTS_PER_SOL
            }),
        );              

        transaction.feePayer = publicKey;
        let blockhashObj = await connection.getRecentBlockhash();
        transaction.recentBlockhash = await blockhashObj.blockhash;

        if(transaction) {
          console.log("Txn created successfully");
        }                

        let signed = await provider.signTransaction(transaction);
        let signature = await connection.sendRawTransaction(signed.serialize());
        await connection.confirmTransaction(signature);
    }
}

i think the problem is in this line let signed = await provider.signTransaction(transaction);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that your publicKey variable is a string and not a PublicKey, so when trying to compile your transaction, the compilation fails with the TypeError: y.pubkey.toBase58 is not a function at transaction.ts:264:33.

Instead, you can do:

publicKey = resp.publicKey;

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda