> 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 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.bloxroute.com/bsc/submit-transactions/raw-transaction-construction.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.
