I want to use the below component in a send button in UI.On click of which the logic should execute.
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import React, { useCallback } from 'react';
interface Props {
children: (sendTransaction: OnSendTransaction) => React.ReactNode;
}
type OnSendTransaction = (toPublicKey: string, amount: number) => void;
const SendTransaction: React.FC<Props> = ({ children }) => {
const { connection } = useConnection();
const { publicKey, signTransaction, sendTransaction } = useWallet();
const onSendSPLTransaction = useCallback(
async (toPubkey: string, amount: number) => {
// Some logic
},
[publicKey, sendTransaction, connection]
);
return <>{children(onSendSPLTransaction)}</>;
};
export default SendTransaction;
I am trying to use the wallet provider and send the spl token to another account on a click. I am able to do so for sol with a normal method but not for spl token. Since there are not many example with spl token transfer this is the only one i found.
I am not sure how to use the SendTransaction component to pass the toPublicKey and amount. I am not well versed in typescript and react.
This is snippet from the answer at: How to transfer custom SPL token by '@solana/web3.js' and '@solana/sol-wallet-adapter'