最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Solana web3 js keep gives Cannot read properties of undefined (reading 'negative') while trying to

programmeradmin1浏览0评论

I'm trying to sign a transaction with connected user's wallet, through phantom but I keep getting this error message

Cannot read properties of undefined (reading 'negative')

below is my transaction function

async SendTransaction(from,to){
        console.log(from);
        // const f  = JSON.stringify(from)
        // console.log(f);
        const transaction = new Transaction().add(
            SystemProgram.transfer({
              fromPubkey: new PublicKey(from.publicKey),
              toPubkey: new PublicKey(to),
              lamports: LAMPORTS_PER_SOL / 100,
            }),
          );
          let blockhash = (await connection.getLatestBlockhash("finalized")).blockhash;
          transaction.recentBlockhash = blockhash
          transaction.feePayer = from

        
        //   Sign transaction, broadcast, and confirm
          const signature = await sendAndConfirmTransaction(
            connection,
            transaction,
            [from],
          );
          console.log(signature);
        return transaction
    },

I'm trying to sign a transaction with connected user's wallet, through phantom but I keep getting this error message

Cannot read properties of undefined (reading 'negative')

below is my transaction function

async SendTransaction(from,to){
        console.log(from);
        // const f  = JSON.stringify(from)
        // console.log(f);
        const transaction = new Transaction().add(
            SystemProgram.transfer({
              fromPubkey: new PublicKey(from.publicKey),
              toPubkey: new PublicKey(to),
              lamports: LAMPORTS_PER_SOL / 100,
            }),
          );
          let blockhash = (await connection.getLatestBlockhash("finalized")).blockhash;
          transaction.recentBlockhash = blockhash
          transaction.feePayer = from

        
        //   Sign transaction, broadcast, and confirm
          const signature = await sendAndConfirmTransaction(
            connection,
            transaction,
            [from],
          );
          console.log(signature);
        return transaction
    },
Share Improve this question edited May 18, 2022 at 15:09 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Apr 5, 2022 at 16:29 CyberheroCyberhero 421 silver badge6 bronze badges 5
  • You sure the issue is in this file? No negative here. – kissu Commented Apr 5, 2022 at 16:34
  • Have you checked that phantom is connected to a wallet? – DaveTheAl Commented Apr 18, 2022 at 14:52
  • I'm getting this too. Have you solved it? – chrisbjr Commented Aug 31, 2022 at 13:26
  • See also solana.stackexchange./questions/2127/… – mikemaccana Commented Sep 8, 2022 at 13:46
  • How did you solve this issue? I'm facing exactly the same issue, even while I provide everything like requested: const sendSolInstruction = SystemProgram.transfer({ fromPubkey: new PublicKey(connectData.public_key), toPubkey: new PublicKey(connectData.public_key), lamports: 5000, }); transaction.add(sendSolInstruction); try { const signature = await sendAndConfirmTransaction(connection, transaction,[ dappKeyPair ]); console.log(signature) } catch (error) { console.log(error); } – aronyi Commented Jul 2, 2024 at 17:02
Add a ment  | 

1 Answer 1

Reset to default 6

I faced the exact same issue.

In my case the problem was with the value I was passing in as feePayer. We need to be passsing a PublicKey object just like we do for toPubKey and fromPubKey in the SystemProgram.transfer method. However I was passing in the publicKey string. I, instead passed a PublicKey object ( new PublicKey(fromAddress) ) as the value for feePayer and it started working.

Please verify your feePayer value.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论