Skip to content

The Polygon Scan APIs for python based from the fork of bscscan-python

License

Notifications You must be signed in to change notification settings

tarsil/polygonscan-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polygonscan-python

A complete Python API for PolygonScan.com

Powered by PolygonScan.com APIs

Available on PyPI

A fork of the bscscan-python package.

A minimal, yet complete, Python API for polygonscan.com.

This package was based on bscscan-python and applied to the polygon network. A special thanks to the creator.

Available on PyPI. Powered by polygonscan.com APIs.


Endpoints

The following endpoints are provided:

Accounts (source)

  • get_matic_balance
  • get_matic_balance_multiple
  • get_normal_txs_by_address
  • get_normal_txs_by_address_paginated
  • get_internal_txs_by_address
  • get_internal_txs_by_address_paginated
  • get_internal_txs_by_txhash
  • get_internal_txs_by_block_range_paginated
  • get_erc20_token_transfer_events_by_address
  • get_erc20_token_transfer_events_by_contract_address_paginated
  • get_erc20_token_transfer_events_by_address_and_contract_paginated
  • get_erc721_token_transfer_events_by_address
  • get_erc721_token_transfer_events_by_contract_address_paginated
  • get_erc721_token_transfer_events_by_address_and_contract_paginated
  • get_mined_blocks_by_address
  • get_mined_blocks_by_address_paginated
Contracts (source)

  • get_contract_abi
  • get_contract_source_code
Transactions (source)

  • get_contract_execution_status
  • get_tx_receipt_status
Blocks (source)

  • get_block_reward_by_block_number
  • get_est_block_countdown_time_by_block_number
  • get_block_number_by_timestamp
GETH/Parity Proxy (source)

  • get_proxy_block_number
  • get_proxy_block_by_number
  • get_proxy_uncle_by_block_number_and_index
  • get_proxy_block_transaction_count_by_number
  • get_proxy_transaction_by_hash
  • get_proxy_transaction_by_block_number_and_index
  • get_proxy_transaction_count
  • get_proxy_transaction_receipt
  • get_proxy_call
  • get_proxy_code_at
  • get_proxy_storage_position_at
  • get_proxy_gas_price
  • get_proxy_est_gas
Tokens (source)

  • get_total_supply_by_contract_address
  • get_acc_balance_by_token_and_contract_address
Gas Tracker (source)

  • get_est_confirmation_time
  • get_gas_oracle
Stats (source)

  • get_total_matic_supply
  • get_matic_last_price

If you think that a newly-added method is missing, kindly open an issue as a feature request and I will do my best to add it.

Installation

Before proceeding, you should register an account on polygonscan.com and generate a personal API key to use.

If you wish to have access to the PRO endpoints, you should obtain elevated privileges via PolygonScans's subscription service.

Install from source:

pip install git+https://github.com/tarsil/polygonscan-python

Alternatively, install from PyPI:

pip install polygonscan-python

Unit tests

In bash, test that everything looks OK on your end using your YOUR_API_KEY (without quotation marks) before proceeding:

bash run_tests.sh YOUR_API_KEY

This will regenerate the logs under logs/ with the most recent results and the timestamp of the execution.

Usage

In python, create a client with your personal polygonscan.com API key:

E.g:

from polygonscan import PolygonScan

with PolygonScan("API_KEY",False) as matic:
    print(matic.get_matic_balance(address="0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a"))

Then you can call all available methods, e.g.:

matic.get_matic_balance(address="0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a")

> '40891631566070000000000'

You can also choose one of the other testnets:

matic = PolygonScan(YOUR_API_KEY, net="ropsten") # net name is case-insensitive, default is main

Examples

Examples (arguments and results) for all methods may be found as JSON files here. For example, if you want to use the method get_block_number_by_timestamp, you can find the supported arguments and the format of its output in its respective JSON file:

{
  "method": "get_block_number_by_timestamp",
  "module": "blocks",
  "kwargs": {
    "timestamp": "1578638524",
    "closest": "before"
  },
  "log_timestamp": "2020-10-28-12:34:44",
  "res": "9251482"
}

where kwargs refer to the required named arguments and res refers to the expected result if you were to run:

eth.get_block_number_by_timestamp(timestamp="1578638524", closest="before")

> '9251482'

Disclaimer: Those examples blindly use the arguments originally showcased here and the selected wallets/contracts do not reflect any personal preference. You should refer to the same source for additional information regarding specific argument values.

Issues

For problems regarding installing or using the package please open an issue. Kindly avoid disclosing potentially sensitive information such as your API keys or your wallet addresses.

Feel free to leave a ⭐ if you found this package useful.


Powered by polygonscan.com APIs.

About

The Polygon Scan APIs for python based from the fork of bscscan-python

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published