Reputation: 163
It has been a real big issue finding solution to the error on Solana Transaction API I have sent several messages to the tech discord group and the Telegram group and still did not find any of the Solana tech developers who can solve the issue. I have read and applied all the suggestions written on their example codes, and many of their documents on their website, and all these are working or solving the issue. I also noticed I am not the only one going through the issue and haven't gotten a satisfying solution to the error.
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
<!-- Production (minified) -->
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.min.js"></script>
This is the code:
await window.solana.connect();
const provider = window.solana;
console.log("Public key of the emitter: ",provider.publicKey.toString());
var connection = new solanaWeb3.Connection(
solanaWeb3.clusterApiUrl('devnet'),
);
var recieverWallet = new solanaWeb3.PublicKey("FjXye8TxWjxCvA9wmL8vhfzmQXfxjp5LYhBBZCHY4h5B");
transaction = new solanaWeb3.Transaction();
transaction.add(
solanaWeb3.SystemProgram.transfer({
fromPubkey: provider.publicKey,
toPubkey: recieverWallet,
lamports: (solanaWeb3.LAMPORTS_PER_SOL * 5)
}),
);
const signature = await solanaWeb3.sendAndConfirmTransaction(connection,transaction,[provider]);
And the error is : enter image description here
TypeError: unexpected type, use Uint8Array at checkArrayTypes (nacl-fast.js:2165:13)
Upvotes: 1
Views: 6580
Reputation: 2107
So the problem is that you're using the provider
from a specific wallet to "sign" for a transaction incorrectly.
The sendAndConfirmTransaction
method expects a signer
where you have a provider
. That's the current error you are getting.
With Phantom, you have to use the provider to send the transaction like this:
await window.solana.signAndSendTransaction(transaction);
If you use the wallet-adapter, you can reference the same function across all wallets as seen in the cookbook examples.
Upvotes: 2