> For the complete documentation index, see [llms.txt](https://docs-wallet.magiceden.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-wallet.magiceden.io/evm/sending-a-transaction.md).

# Sending a Transaction

To send a transaction, you must construct a valid transaction object and then prompt the user to sign the transaction with their private key.

## Direct Sending

Triggering this directly would look make use of the provider `request` function and look like this:

```javascript
const result = await provider.request({
        method: 'eth_sendTransaction',
        params: [
          {
            from: address,
            to: '0x6aDdF38602487b7a159D926bc08151eBaEEF2B70',
            value: '0x0',
            gasLimit: '0x5028',
            gasPrice: '0x2540be400',
            type: '0x0',
          },
        ],
});
```

However, there are several other parts of a transaction object that might need to be specfied, and therefore it is suggested to make use of a web3 library that abstracts away a lot of this complexity, like [ethers.js](https://docs.ethers.org/v5/)

## Using Ethers.js

Below is a code example that builds out a valid transaction object and prompts the transaction to send with permission from the signer, utilizing ethers.js

```typescript
import { TransactionResponse, Web3Provider } from "@ethersproject/providers";
import { utils } from "ethers";

/**
 * Send 1 wei from the connected wallet to itself
 * @param {Web3Provider} provider a web3 provider
 * @returns {Promise<TransactionResponse>} a raw transaction object
 */
export async function sendTransaction(
  provider: Web3Provider
): Promise<TransactionResponse> {
  try {
    const signer = provider.getSigner();
    const address = await signer.getAddress();
    const gasPrice = await provider.getGasPrice();
    const transactionParameters = {
      nonce: await provider.getTransactionCount(address),
      gasPrice,
      gasLimit: utils.hexlify(100000),
      to: address,
      from: address,
      value: utils.parseUnits("1", "wei"),
    };
    return signer.sendTransaction(transactionParameters);
  } catch (error) {
    console.warn(error);
    throw new Error("Error sending transaction");
  }
}

```

You'll notice a lot more structure with the parameters needed to invoke `signer.sendTransaction` . Due to the abstraction and wide use of libraries like ethers, we recommend this method when constructing your evm transactions. &#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
