# Sending a Transaction

Sending a transaction on the Solana network requires the creation of a Transaction object, followed by the transaction being signed and submitted by the user's Magic Eden wallet.

{% hint style="info" %}
:green\_book:**Solana Web3js**

For more information on interacting with Solana on the client side, check out the docs for [Solana Web3js](https://solana-labs.github.io/solana-web3.js/)

For more general Solana development information, check out the courses and resources offered on [Soldev](https://www.soldev.app/)
{% endhint %}

## Creating a Transaction

Before you can sign or send a transaction, you must create one! Below is a basic example of creating a tx that has a user send funds right back to themselves

```javascript
import {
  Transaction,
  SystemProgram,
  Connection,
  PublicKey,
} from "@solana/web3.js";

/**
 * Creates an example transaction to transfer 100 lamports to the same account.
 * @param {String} publicKey a wallet public key
 * @param {Connection} connection an RPC connection
 * @returns {Transaction} a transaction
 */
export const createTransaction = async (
  publicKey: PublicKey,
  connection: Connection
): Promise<Transaction> => {
  const latestBlockhash = (await connection.getLatestBlockhash()).blockhash;
  const transaction = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: publicKey,
      toPubkey: publicKey,
      lamports: 1000,
    })
  );
  transaction.feePayer = publicKey;
  transaction.recentBlockhash = latestBlockhash;

  return transaction;
};

```

## Signing and Sending a Transaction

Once the transaction is created, you can then prompt the user to sign and send it using the `signAndSendTransaction` method exposed by the provider

```javascript
import { Transaction } from "@solana/web3.js";

import { MagicEdenProvider } from "../types/types";

/**
 * Signs and sends the given created transaction using the MagicEdenProvider object.
 * @param {MagicEdenProvider} provider The MagicEdenProvider object
 * @param {Transaction} transaction The transaction to sign and send
 * @returns {Promise<string>} A promise that resolves to the signature of the transaction
 */
export const signAndSendTransaction = async (
  provider: MagicEdenProvider,
  transaction: Transaction
): Promise<string> => {
  try {
    const { signature } = await provider.signAndSendTransaction(transaction);
    return signature;
  } catch (error) {
    console.warn(error);
    throw new Error(
      "An unexpected error occured while signing the transaction."
    );
  }
};

```

All of this functionality and more can be found at our [Solana Demo](https://github.com/Tcadle434/me-wallet-solana-react/blob/main/src/App.tsx), so feel free to check it out if you want to learn more about handling wallet functionality when connecting directly to the Magic Eden wallet.

{% hint style="info" %}
**Note** :pencil:\
The signAndSendTransaction method supports both Legacy and [Versioned Transactions](https://solana.com/docs/advanced/versions). The newer Versioned Txs allow for [Address Lookup Tables](https://solana.com/docs/advanced/lookup-tables)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-wallet.magiceden.io/solana/sending-a-transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
