Hey everyone, I’m stuck with two issues while trying to transfer an NFT on Solana using JavaScript. Here’s what’s going on:
I’ve got a script that moves an NFT from Alice’s wallet (where all my minted NFTs are) to a buyer’s wallet. It works fine when I use connection.sendTransaction(), but when I try using Phantom’s signAndSendTransaction() method, I get an ‘RPC request rejected’ error. What could be causing this?
Currently, I’m using a feePayer account with a known keypair. But if I want users to connect their own wallets using a connectWallet button, I’ll only have their public key. How do I transfer the NFT from Alice’s wallet to a user who just connected and clicked ‘buy’?
Here’s a simplified version of the code I’m working with:
I’ve encountered similar issues when working with Solana NFT transfers. For the first problem, it’s likely due to the transaction not being properly signed. When using Phantom’s signAndSendTransaction(), you need to ensure that all required signers have signed the transaction before sending it. In your case, Alice’s wallet needs to sign first.
As for the second issue, transferring from Alice’s wallet to a newly connected user’s wallet can be tricky. You’ll need to create a server-side endpoint that holds Alice’s private key securely. When a user connects and clicks ‘buy’, your client-side code should send a request to this endpoint with the buyer’s public key. The server can then construct and sign the transaction using Alice’s key before returning it to the client for the buyer to sign and send.
Remember to handle errors gracefully and always verify transaction success on-chain. Also, consider implementing a retry mechanism for failed transactions due to Solana’s occasional congestion.
hey there! i’ve dealt with similar probs. for the phantom issue, make sure alice signs first before using signAndSendTransaction(). for transferring to new users, you’ll need a server endpoint with alice’s private key. when someone buys, send their pubkey to the server, build the tx there, then send it back for the buyer to sign. hope this helps!
hey ava61! those nft transfer issues can be tricky, right? i’m curious, have you tried using a different wallet provider besides phantom? sometimes switching things up can help pinpoint the problem
for the first issue, it sounds like a signing problem. maybe try explicitly signing with alice’s wallet before calling phantom’s method? something like:
as for transferring to newly connected wallets, that’s a bit more complex. have you considered using a backend service to handle the sensitive parts? it could manage alice’s keys securely and do the heavy lifting.
what’s your overall goal with this nft transfer system? are you building a marketplace or something else cool? i’d love to hear more about your project!