[英]"TypeError: x.pubkey.toBase58 is not a function" in phantom wallet...transfer sol to another account in JavaScript with@solana/web3.js
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.
问题是您将字符串作为 toPubKey 传递 - 应该是 PublicKey 实例。 Try this:
尝试这个:
let transaction = new solanalib.Transaction().add(
solanalib.SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: new solanalib.PublicKey('GJ7bZskjGFqph51T88W2E1A1TeT1YVuuFM8atQAtVhSz'),
lamports: solanalib.LAMPORTS_PER_SOL,
})
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.