Hyperledger Besu – Deploying a SmartContract to a Local Network Using Brownie

besubrowniehyperledgermigration

EDIT: In short, I want to use Brownie to deploy smartContracts to HyperLedger-Besu network on my local machine. For some reason, it doesn't work, so I wanted to ask if anyone here had experience with such an issue. I described my specific problem in more detail below.

I tried to deploy a basic Migrate.sol smartContract on my local instance of HyperLedger-Besu (named besulocal) by using Brownie.

I added its configuration to the brownie's network-config.yaml

  - name: HyperLedger-Besu
    chainid: 1337
    id: besulocal
    host: http://localhost:8545
    block_time: 5

Then confirmed it indeed works by checking the balance of pre-funded account acct. (Screenshoot below)
enter image description here

However, when I am trying to migrate the Migrations.sol to the besulocal
I get this Error:

 Transaction sent: 0xc3f86ca503d3d5f26dc57b30ee3039c4ecd4641ee7d0e5c8c223bd9032d38a41
      Gas price: 0.0 gwei   Gas limit: 191019   Nonce: 33
      File "<console>", line 1, in <module>
      File "/usr/local/lib/python3.8/dist-packages/eth_brownie-1.18.1-py3.8.egg/brownie/network/contract.py", line 532, in __call__
        return tx["from"].deploy(
      File "/usr/local/lib/python3.8/dist-packages/eth_brownie-1.18.1-py3.8.egg/brownie/network/account.py", line 510, in deploy
        receipt, exc = self._make_transaction(
      File "/usr/local/lib/python3.8/dist-packages/eth_brownie-1.18.1-py3.8.egg/brownie/network/account.py", line 759, in _make_transaction
        receipt = TransactionReceipt(
      File "/usr/local/lib/python3.8/dist-packages/eth_brownie-1.18.1-py3.8.egg/brownie/network/transaction.py", line 221, in __init__
        target=self._await_confirmation, args=(tx["blockNumber"], required_confs), daemon=True
      File "/usr/local/lib/python3.8/dist-packages/web3-5.27.0-py3.8.egg/web3/datastructures.py", line 51, in __getitem__
        return self.__dict__[key]  # type: ignore
    KeyError: 'blockNumber'

The interesting thing is that when I try to deploy to ganache-cli everything works as intended, but fails on besulocal enter image description here

This is my deployment-script:

from brownie import Migrations, accounts

    def main():
    
        acct = accounts.load('besulocal_account') #Account Pre-funded with ETH
        Migrations.deploy({'from': acct})

Would appreciate if anyone had any idea on how to deal with this.

NOTE: ganache-cli and besulocal are using the same port, but they are not active simultaneously. I shut down ganache-cli before using besulocal and vice versa.

EDIT2: The first answer mentioned that signer might be an issue. So I tried to transfer some ETH from pre-funded account to another address. And I indeed got the same error; however, after checking the balances, I noticed the transfer did indeed pass through regardless of the error. See screenShoot below:
enter image description here

Best Answer

The problem is due to Besu not fully following the standard JSON-RPC API for eth_getTransactionByHash.

After signing the tx, brownie checks the status of the tx using eth_getTransactionByHash and looks for blockNumber field. API standard says that filed should be null if the tx is pending, or equal to the block number if the tx is mined.

On the contrary, Besu's response does not contain the blockNumber field in case of pending txs, and this causes the error.

Example of Besu response for a pending tx:

{
  "jsonrpc" : "2.0",
  "id" : 6,
  "result" : {
    "from" : "0x627306090abab3a6e1400e9345bc60c78a8bef57",
    "gas" : "0x5208",
    "gasPrice" : "0x2540be400",
    "hash" : "0xfe6f9abeacbe186f6ee5edd811228e0710631c3569ee8bd45ca67c46146c762c",
    "input" : "0x",
    "nonce" : "0x32",
    "to" : "0xf12b5dd4ead5f743c6baa640b0216200e89b60da",
    "value" : "0x2",
    "v" : "0xa96",
    "r" : "0x325fd22b695b5f8e54cab34ae558373a9a15229a6cf8614d60fa7bcdc1493abf",
    "s" : "0xf1c739e11f356c7a59e8b37e36f91c423ce0298bfd089780415c60ed2652f3c",
    "chainId" : "0x539",
    "publicKey" : "0xaf80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59",
    "raw" : "0xf866328502540be40082520894f12b5dd4ead5f743c6baa640b0216200e89b60da0280820a96a0325fd22b695b5f8e54cab34ae558373a9a15229a6cf8614d60fa7bcdc1493abfa00f1c739e11f356c7a59e8b37e36f91c423ce0298bfd089780415c60ed2652f3c"
  }
}   

Example in case of mined transaction:

{
  "jsonrpc" : "2.0",
  "id" : 6,
  "result" : {
    "blockHash" : "0x22a9a2ba92fa46aacd2caddba0762f7dac2eba1a9baa85a07a097fcffb12976f",
    "blockNumber" : "0x1df",
    "chainId" : "0x539",
    "from" : "0x627306090abab3a6e1400e9345bc60c78a8bef57",
    "gas" : "0x5208",
    "gasPrice" : "0x2540be400",
    "hash" : "0x7dbaf945a3f971b26a48ee3e0eba62348bcece160ba356def95f70aa85dc032f",
    "input" : "0x",
    "nonce" : "0x12",
    "publicKey" : "0xaf80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59",
    "raw" : "0xf866128502540be40082520894f12b5dd4ead5f743c6baa640b0216200e89b60da0180820a96a0da2be02538d4f505a79c16eab693e54b8529e9b72ef3cf69ed482141a1273744a015c1c2d81decef6226b1c3f390b6c34cbea38af788c3e44e6e7e83ca0c759fa6",
    "to" : "0xf12b5dd4ead5f743c6baa640b0216200e89b60da",
    "transactionIndex" : "0x0",
    "value" : "0x1",
    "v" : "0xa96",
    "r" : "0xda2be02538d4f505a79c16eab693e54b8529e9b72ef3cf69ed482141a1273744",
    "s" : "0x15c1c2d81decef6226b1c3f390b6c34cbea38af788c3e44e6e7e83ca0c759fa6"
  }
}

I opened a dedicated issue on the official Besu repo, and now it's fixed with PR3906. Brownie should be able to work fine with the next Besu's release.

Related Topic