Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup Address and Transactions on a Geth node using Web3.py #1

Open
johnsBeharry opened this issue Aug 10, 2018 · 1 comment
Open

Comments

@johnsBeharry
Copy link
Member

Estimate: 8h
Due: 2018-08-31
Scenario: Lookup a transaction by id
When a "GET" request is made to "/tx/:transactionId"
Then the response status is "200"
And the response content type is "application/json"
And the response data is similar to:
"""
{
    "data": {
        "to": ...
        "from": ...
    }
}
"""

Scenario: Get transactions and balance of an address
When a "GET" request is made to "/address/:address"
Then the response status is "200"
And the response content type is "application/json"
And the response data is similar to:
"""
{
    "data": {
        "balance": 123,
        "transactions": [...]
    }
}
"""

NOTES

Suggested development approach:

  1. Get Geth running locally and connect to it using metamask or other Ethereum client
  2. Once you have validate RPC connection is working with metamask, start coding a Flask web service
  3. Install web3.py and import into your Flask application
  4. Connect to the local Geth node, and use web3.py to fetch the blockchain data

You may need some local test Ether to create transactions - Geth may have some cli arguments that give you addresses with some Ether when the node initializes.

If you are running into trouble with Geth, then just install Ganache which is a one click setup and has a GUI - you can also connect to it with Metamask.

@micey969
Copy link
Contributor

REPORT

  1. Get Geth running locally and connect to it using metamask or other Ethereum client

    • Finding a tutorial to set up Geth locally wasn't a problem. I found one that I could easily follow and within 3 minutes it was up and running.

    • Connecting it to metamask as well wasn't that hard after I decrypted the addresses and imported the accounts.

    • Problems

      • Even with the accounts showing in metamask, every time I tried to do a transaction, metamask would report a failed message ("Error: Invalid Sender"). When I researched the error message, a common answer as to the cause of the issue was that the network is not EIP 155 compliant and the chainID and networkID used to setup Geth needed to be the same. I decided to restart Geth, following the instructions of my search. However, the issue still persist.

        The following day, I tried it again and this time, I got no errors. The Geth terminal was finally registering that a transaction was made. However it was stuck in pending mode in both metamask and the Geth terminal. This issue persist whole day. Not wanting to be waste anymore time, I switched to the Ganache GUI.

  2. Install web3.py and import into your Flask application

    • A simple run of the command pip install web3 got the web3.py package imported into my Flask application.
    • Following the documentation, finding the functions that I needed to complete the task was easy enough.
  3. Connect to the local Geth node, and use web3.py to fetch the blockchain data

    • With the Ganache GUI set up and web3 imported into my Flask application, I could create transactions to get test data to work with.

    • First Scenario

      Scenario: Lookup a transaction by id
      When a "GET" request is made to "/tx/:transactionId"
      Then the response status is "200"
      And the response content type is "application/json"
      And the response data is similar to:
      """
      {
          "data": {
              "to": ...
              "from": ...
          }
      }
      """

      Getting a transaction by transaction hash

      Expected Behaviour:

      • pass tranasaction hash as param
      • return sender, receiver and value

      Actual Behaviour:

      • returns an AttributeDict
      • returns a full block of code with data pertaining to both the transaction and the ethereum node

      Solution:

      • The returned object behaves similarly to a Python dictionary, so I was able to returned only the data that I needed by referencing their key values (to, from, value).
    • Second Scenario

      Scenario: Get transactions and balance of an address
      When a "GET" request is made to "/address/:address"
      Then the response status is "200"
      And the response content type is "application/json"
      And the response data is similar to:
      """
      {
          "data": {
              "balance": 123,
              "transactions": [...]
          }
      }
      """

      Returning an address balance

      Expected Behaviour:

      • return balance in ether

      Actual Behaviour:

      • returns balance in wei

      Solution:

      • This was left as is for now because of it's accuracy.

      Returning an address' transaction history

      Expected Behavior:

      • pass address as a param

      • returns a list of transaction by an address

      Actual Behavior:

      • no web3 API available for this procedure

      Solution:

      • scan entire blockchain for transactions made from or to the address
      • Problem:
        • Performance: looping through the entire blockchain data every time this function is called is not optimized. However, to save the data for faster referencing from a database, this method would still be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants