> For the complete documentation index, see [llms.txt](https://docs.bloxroute.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bloxroute.com/bsc/submit-transactions/raw-transaction-construction.md).

# Raw Transaction Construction

The `blxr_tx` endpoint expects raw transaction bytes. These are usually built using libraries like **web3** or **ethers**.\
Below are examples showing how to:

* Create and send a simple transfer via `blxr_tx`
* Create and send a token swap transaction via `blxr_tx`

{% tabs %}
{% tab title="Transfer - Node.js" %}

```javascript
const WebSocket = require('ws')
const EthereumTx = require('ethereumjs-tx').Transaction
// Needed for BSC
// const Common = require('ethereumjs-common').default
const Web3 = require('web3')

const web3 = new Web3('PROVIDER_URL')

const account = 'YOUR_ADDRESS'

const privateKey = Buffer.from(
  'YOUR_PRIVATE_KEY',
  'hex',
)
// const BSC = Common.forCustomChain(
//   'mainnet',
//   {
//       name: 'Binance Smart Chain Mainnet',
//       networkId: 56,
//       chainId: 56,
//       url: 'https://bsc-dataseed.binance.org/'
//   },
//   'istanbul',
// )

const main = async () => {
  const tx = new EthereumTx({
      to: 'TO_ADDRESS',
      nonce: nonce,
      // Pass in decimal number for fields below
      gasPrice: web3.utils.toHex(),
      gas: web3.utils.toHex(),
      value: web3.utils.toHex(),
      chainId: 1
      // If using BSC
      // chainId: 56
    } //, { common: BSC } 
  )
  tx.sign(privateKey)

  const serializedTx = tx.serialize()
  const rawTx = serializedTx.toString('hex')
  
  const ws = new WebSocket(
    "ws://127.0.0.1:28333/ws", 
    {
      headers: { 
        "Authorization" : <YOUR-AUTHORIZATION-HEADER>
      },
      rejectUnauthorized: false,
    }
  );

  function proceed() {
    ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "${rawTx}"}}`)
  }

  function handle(response) {
    console.log(response.toString()) // Or process it generally
  }
  ws.on('open', proceed)
  ws.on('message', handle)
```

{% endtab %}
{% endtabs %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.bloxroute.com/bsc/submit-transactions/raw-transaction-construction.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
