let transaction = new solanalib.Transaction().add( solanalib.SystemProgram.transfer({ fromPubkey: publicKey, toPubkey: 'GJ7bZskjGFqph51T88W2E1A1TeT1YVuuFM8atQAtVhSz', lamports: solanalib.LAMPORTS_PER_SOL, }), ); transaction.feePayer = publicKey; let blockhashObj = await connection.getRecentBlockhash(); transaction.recentBlockhash = await blockhashObj.blockhash; if (transaction) { console.log('Txn created successfully'); } else { console.log('Sorry'); } const signedTransaction = await window.solana.signTransaction(transaction); const signature = await connection.sendRawTransaction(signedTransaction.serialize()); console.log('Signature: ', signature);
I've just managed to solve this issue. The problem is that you are passing a string as the toPubKey - should be a PublicKey instance. Try this:
let transaction = new solanalib.Transaction().add(
solanalib.SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: new solanalib.PublicKey('GJ7bZskjGFqph51T88W2E1A1TeT1YVuuFM8atQAtVhSz'),
lamports: solanalib.LAMPORTS_PER_SOL,
})
);
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.