简体   繁体   中英

Can't get wallet signer @solana-labs/web3.js while trying to send USDC

I'm trying to send USDC based on the answer in this thread - How to send USDC-SPL using @solana-labs/web3.js but he used the private key in his answer and I can't seem to get the signer for a real wallet. I keep getting errors like this:

Argument of type 'WalletAdapter' is not assignable to parameter of type 'Signer'. Property 'secretKey' is missing in type 'WalletAdapter' but required in type 'Signer'.

My code:

var connection = new web3.Connection(web3.clusterApiUrl("devnet"));
    // Construct wallet keypairs
    var fromWallet = wallet;
    var toWallet =to;
    // Construct my token class
    
    var USDC_pubkey = new web3.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
    var USDC_Token = new splToken.Token(
      connection,
      USDC_pubkey,
      splToken.TOKEN_PROGRAM_ID,
      fromWallet
    );

By design, wallets do not allow dapps to directly access the private key of a wallet. Otherwise, a malicious dapp could easily collect all of its users private keys and steal their funds.

Instead, wallets provide an interface for signing transactions. From your code snippet, it's not clear which wallet you're using, but you may want to use the solana-labs/wallet-adapter package to handle these connections. You can follow the steps at https://github.com/solana-labs/wallet-adapter/ to setup your dapp with any wallet!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM