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
    },
TylerH
  • 20,799
  • 66
  • 75
  • 101
Cyberhero
  • 32
  • 6

1 Answers1

1

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.

akshayr
  • 11
  • 1