'"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);
Solution 1:[1]
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,
})
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gal liberman |
