# Transaction Encoding

Submitting transactions to the PFL Relay is done using a JSON-RPC endpoint similar to `eth_sendRawTransaction` which means that a knowledge of how to encode transactions into hex (the wire format) is necessary.

Transactions are usually constructed and sent using one of the higher-level web3 libraries such as web3py or web3.js, to prepare a transaction for sending we would usually do something like:

```python
pfl_contract = web3.eth.contract(address=PFL_CONTRACT_ADDRESS, abi=SOME_ABI)

example_tx_base = {
    'from': '0x1',
    'nonce': 0,
    'gasPrice' : 45,
    'gas': 500_000,
    'value': 1000,
    'chainId': 137,
}

some_abi_args = {}

example_tx = pfl_contract.functions.submitFlashBid(
  **args
).buildTransaction(example_tx_base)

signed_example_tx = web3.eth.account.sign_transaction(example_tx, PRIVATE_KEY)
```

Under the hood, when we make a web3 call like this the library is first encoding our transaction object into a standardized hex representation before making a JSON-RPC call to the above endpoint using whatever transport mechanism you have your web3 library configued to use (usually HTTP,  WebSockets or IPC).

To simply retrieve the hexadecimal encoded representation of our transaction as is required for creating a PFL bundle instead of sending to the RPC, we can simply do:

```
print('data: ', signed_example_tx.hex())
```

This value could then be used to make a raw JSON-RPC call without your web3 library, like so:

```bash
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":[{see above}],"id":1}'
// Response
{
  "id":1,
  "jsonrpc": "2.0",
  "result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
```

For more information, see the Ethereum JSON-RPC documentation [here](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction).


---

# 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://fastlane-labs.gitbook.io/polygon-fastlane/key-concepts/transaction-encoding.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.
