Magic Eden Wallet Developer Docs
  • 👋Welcome
    • Wallet Introduction
  • 📙Bitcoin
    • Diving into Bitcoin
    • Detecting the Provider
    • Connecting to the Wallet
    • Signing a Message
    • Signing a Transaction
    • Sending BTC
    • Provider API Methods
    • Provider Events
    • FAQs
  • 📗Solana
    • Diving Into Solana
    • Solana Wallet Adapter
    • Connect Directly to the ME Solana Provider
    • Signing a Message
    • Sending a Transaction
    • Provider API Methods
    • Provider Events
    • FAQs
  • 📘EVM
    • Diving into the EVM
    • Connect Directly to the ME EVM Provider
    • Signing a Message
    • Sending a Transaction
    • Library Integrations
      • Wallet Connect
      • Rainbow Kit
      • Wagmi
    • Provider API Methods
    • Provider Events
    • FAQs
  • ❓Resources
    • Demo Apps
    • Logos and Brand Assets
Powered by GitBook
On this page
  • Creating a Transaction
  • Signing and Sending a Transaction
  1. Solana

Sending a Transaction

PreviousSigning a MessageNextProvider API Methods

Last updated 10 months ago

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.

Solana Web3js

For more information on interacting with Solana on the client side, check out the docs for

For more general Solana development information, check out the courses and resources offered on

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

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

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 , 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.

Note The signAndSendTransaction method supports both Legacy and . The newer Versioned Txs allow for

📗
📗
Solana Web3js
Soldev
Solana Demo
📝
Versioned Transactions
Address Lookup Tables