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:

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:

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

Last updated