phantom / deep-link-demo-app

179 stars 25 forks source link

example send any transaction to phantom wallet NOT transfer #10

Closed NavidHosseini closed 2 years ago

NavidHosseini commented 2 years ago

Hello, can someone give an example to send a transaction other than transfer to Phantom

` const createTransferTransaction = async () => { if (!phantomWalletPublicKey) throw new Error("missing public key from user"); var programId = new PublicKey("5Zcag1obaSA1CXLT6qusdbeiApeG4PVANtzsFmJZUMYj") let instruction = new TransactionInstruction({ keys: [{ pubkey: phantomWalletPublicKey, isSigner: false, isWritable: true }], programId, data: Buffer.alloc(0), }); let transaction = new Transaction().add( instruction );

transaction.feePayer = phantomWalletPublicKey;

const anyTransaction: any = transaction;

anyTransaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
return transaction;
 };
 const signAndSendTransaction = async () => {
const transaction = await createTransferTransaction();
const serializedTransaction = transaction.serialize({
  requireAllSignatures: false,
  });

const payload = {
  session,
  transaction: bs58.encode(serializedTransaction),
};
const [nonce, encryptedPayload] = encryptPayload(payload, sharedSecret);

const params = new URLSearchParams({
  dapp_encryption_public_key: bs58.encode(dappKeyPair.publicKey),
  nonce: bs58.encode(nonce),
  redirect_link: onSignAndSendTransactionRedirectLink,
  payload: bs58.encode(encryptedPayload),
});
addLog("Sending transaction...");
const url = buildUrl("signAndSendTransaction", params);
Linking.openURL(url);
  };`

I try to send transaction to phantom wallet ,but I got errorMessage "Somthing went wrong" with errorCode:"-32603"