title: How to transfer custom SPL token by '@solana/web3.js' and '@solana/sol-wallet-adapter'
body: <p>I am trying to transfer a custom SPL token with the solana-wallet adapter. However I am having trouble getting the wallet's secret key/signing the transaction.</p>
  <p>I've looked at these answers for writing the transfer code, but I need to get the Signer and I have trouble figuring out how with solana-wallet adapter:</p>
  <p><a href="https://stackoverflow.com/questions/68166964/how-can-you-transfer-sol-using-the-web3-js-sdk-for-solana">How can you transfer SOL using the web3.js sdk for Solana?</a></p>
  <p><a href="https://stackoverflow.com/questions/68236211/how-to-transfer-custom-token-by-solana-web3-js">How to transfer custom token by &#39;@solana/web3.js&#39;</a></p>
  <p>These examples hardcode the secret key and since I'm using a wallet extension this is not possible.</p>
  <p>According to this issue on the webadapter repo <a href="https://github.com/solana-labs/wallet-adapter/issues/120" rel="nofollow noreferrer">https://github.com/solana-labs/wallet-adapter/issues/120</a> you need to:</p>
  <ol>
  <li>Create a @solana/web3.js Transaction object and add instructions to it</li>
  <li>Sign the transaction with the wallet</li>
  <li>Send the transaction over a Connection</li>
  </ol>
  <p>But Ii am having difficulty finding examples or documentation as to how to do step 1 and 2.</p>
  <pre><code>const SendTransaction: React.FC&lt;Props&gt; = ({ children }) =&gt; {
      const { connection } = useConnection()
      const { publicKey, sendTransaction } = useWallet()
  
      const onSendSPLTransaction = useCallback(
          async (toPubkey: string, amount: number) =&gt; {
              if (!toPubkey || !amount) return
              const toastId = toast.loading('Processing transaction...')
  
              try {
                  if (!publicKey) throw new WalletNotConnectedError()
                  const toPublicKey = new PublicKey(toPubkey)
                  const mint = new PublicKey('Mint address')
                  const payer = '????' // how to get this Signer
                  const token = new Token(connection, mint, TOKEN_PROGRAM_ID, payer)
                  const fromTokenAccount = await token.getOrCreateAssociatedAccountInfo(publicKey)
                  const toTokenAccount = await token.getOrCreateAssociatedAccountInfo(toPublicKey)
  
                  const transaction = new Transaction().add(
                      Token.createTransferInstruction(
                          TOKEN_PROGRAM_ID,
                          fromTokenAccount.address,
                          toTokenAccount.address,
                          publicKey,
                          [],
                          0
                      )
                  )
  
                  const signature = await sendTransaction(transaction, connection)
  
                  const response = await connection.confirmTransaction(signature, 'processed')
                  console.log('response', response)
                  toast.success('Transaction sent', {
                      id: toastId,
                  })
              } catch (error) {
                  toast.error(`Transaction failed: ${error.message}`, {
                      id: toastId,
                  })
              }
          },
          [publicKey, sendTransaction, connection]
      )
  
      return &lt;&gt;{children(onSendSPLTransaction)}&lt;/&gt;
  }
  </code></pre>