Skip to content

Commit 9dea921

Browse files
committed
Main commit
0 parents  commit 9dea921

File tree

105 files changed

+91764
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+91764
-0
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['0xd73Da844084B84b76cFa29FABf6bAee663678c7a']

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: build
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.8]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install git+https://github.com/tarsil/polygonscan-python.git coverage flake8
22+
- name: Lint with flake8
23+
run: |
24+
# stop the build if there are Python syntax errors or undefined names
25+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
26+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
27+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
28+
# - name: Test with unittest
29+
# run: |
30+
# # bash run_tests.sh ${{ secrets.ETHERSCAN_API_KEY }}
31+
# # bash <(curl -s https://codecov.io/bash)

.github/workflows/python-publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflows will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.8'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# notebooks
2+
*.ipynb
3+
4+
# pyc files
5+
*pyc*
6+
7+
# coverage
8+
*coverage*
9+
10+
# VSCode
11+
.vscode/*
12+
13+
# Sphinx
14+
docs
15+
16+
# eggs
17+
*egg*

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2021 Tiago Silva
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include polygon/configs/stable.json

README.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# polygonscan-python
2+
3+
A minimal, yet complete, Python API for [polygonscan.com](https://polygonscan.com/).
4+
5+
This package was cloned from [bscscan-python](https://github.com/pcko1/bscscan-python) and
6+
readapted to polygon network. A special thanks to the [creator](https://github.com/pcko1).
7+
8+
All standard and pro endpoints are provided.
9+
10+
Available on [PyPI](https://pypi.org/project/polygonscan-python/). Powered by [polygonscan.com APIs](https://polygonscan.com/apis#misc).
11+
12+
___
13+
14+
## Endpoints
15+
16+
The following endpoints are provided:
17+
18+
<details><summary>Accounts <a href="https://polygonscan.com/apis#accounts">(source)</a></summary>
19+
<p>
20+
21+
* `get_matic_balance`
22+
* `get_matic_balance_multiple`
23+
* `get_normal_txs_by_address`
24+
* `get_normal_txs_by_address_paginated`
25+
* `get_internal_txs_by_address`
26+
* `get_internal_txs_by_address_paginated`
27+
* `get_internal_txs_by_txhash`
28+
* `get_internal_txs_by_block_range_paginated`
29+
* `get_erc20_token_transfer_events_by_address`
30+
* `get_erc20_token_transfer_events_by_contract_address_paginated`
31+
* `get_erc20_token_transfer_events_by_address_and_contract_paginated`
32+
* `get_erc721_token_transfer_events_by_address`
33+
* `get_erc721_token_transfer_events_by_contract_address_paginated`
34+
* `get_erc721_token_transfer_events_by_address_and_contract_paginated`
35+
* `get_mined_blocks_by_address`
36+
* `get_mined_blocks_by_address_paginated`
37+
38+
</details>
39+
40+
<details><summary>Contracts <a href="https://polygonscan.com/apis#contracts">(source)</a></summary>
41+
<p>
42+
43+
* `get_contract_abi`
44+
* `get_contract_source_code`
45+
46+
</details>
47+
48+
</details>
49+
50+
<details><summary>Transactions <a href="https://polygonscan.com/apis#transactions">(source)</a></summary>
51+
<p>
52+
53+
* `get_contract_execution_status`
54+
* `get_tx_receipt_status`
55+
56+
</details>
57+
58+
<details><summary>Blocks <a href="https://polygonscan.com/apis#blocks">(source)</a></summary>
59+
<p>
60+
61+
* `get_block_reward_by_block_number`
62+
* `get_est_block_countdown_time_by_block_number`
63+
* `get_block_number_by_timestamp`
64+
65+
</details>
66+
67+
<details><summary>GETH/Parity Proxy <a href="https://polygonscan.com/apis#proxy">(source)</a></summary>
68+
<p>
69+
70+
* `get_proxy_block_number`
71+
* `get_proxy_block_by_number`
72+
* `get_proxy_uncle_by_block_number_and_index`
73+
* `get_proxy_block_transaction_count_by_number`
74+
* `get_proxy_transaction_by_hash`
75+
* `get_proxy_transaction_by_block_number_and_index`
76+
* `get_proxy_transaction_count`
77+
* `get_proxy_transaction_receipt`
78+
* `get_proxy_call`
79+
* `get_proxy_code_at`
80+
* `get_proxy_storage_position_at`
81+
* `get_proxy_gas_price`
82+
* `get_proxy_est_gas`
83+
84+
</details>
85+
86+
<details><summary>Tokens <a href="https://polygonscan.com/apis#tokens">(source)</a></summary>
87+
<p>
88+
89+
* `get_total_supply_by_contract_address`
90+
* `get_acc_balance_by_token_and_contract_address`
91+
92+
</details>
93+
94+
<details><summary>Gas Tracker <a href="https://polygonscan.com/apis#gastracker">(source)</a></summary>
95+
<p>
96+
97+
* `get_est_confirmation_time`
98+
* `get_gas_oracle`
99+
100+
</details>
101+
102+
<details><summary>Stats <a href="https://polygonscan.com/apis#stats">(source)</a></summary>
103+
<p>
104+
105+
* `get_total_matic_supply`
106+
* `get_matic_last_price`
107+
108+
</details>
109+
110+
*If you think that a newly-added method is missing, kindly open an [issue](https://github.com/tarsil/polygonscan-python/issues) as a feature request and I will do my best to add it.*
111+
112+
## Installation
113+
114+
Before proceeding, you should register an account on [polygonscan.com](https://polygonscan.com/)
115+
and [generate a personal API key](https://polygonscan.com/myapikey) to use.
116+
117+
If you wish to have access to the PRO endpoints, you should obtain elevated privileges via PolygonScans's
118+
subscription service.
119+
120+
Install from source:
121+
122+
``` bash
123+
pip install git+https://github.com/tarsil/polygonscan-python
124+
```
125+
126+
Alternatively, install from [PyPI](https://pypi.org/project/polygonscan-python/):
127+
128+
```bash
129+
pip install polygonscan-python
130+
```
131+
132+
## Unit tests
133+
134+
In `bash`, test that everything looks OK on your end using your `YOUR_API_KEY` (without quotation marks)
135+
before proceeding:
136+
137+
``` bash
138+
bash run_tests.sh YOUR_API_KEY
139+
````
140+
141+
This will regenerate the logs under `logs/` with the most recent results and the timestamp of the execution.
142+
143+
## Usage
144+
145+
In `python`, create a client with your personal [polygonscan.com](https://polygonscan.com/) API key:
146+
147+
``` python
148+
from polygonscan import PolygonScan
149+
matic = PolygonScan(YOUR_API_KEY) # key in quotation marks
150+
```
151+
152+
Then you can call all available methods, e.g.:
153+
154+
``` python
155+
matic.get_matic_balance(address="0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a")
156+
157+
> '40891631566070000000000'
158+
```
159+
You can also choose one of the other testnets:
160+
``` python
161+
matic = PolygonScan(YOUR_API_KEY, net="ropsten") # net name is case-insensitive, default is main
162+
```
163+
164+
## Examples
165+
166+
Examples (arguments and results) for all methods may be found as JSON files
167+
[here](https://github.com/tarsil/polygonscan-python/tree/master/logs).
168+
For example, if you want to use the method `get_block_number_by_timestamp`,
169+
you can find the supported arguments and the format of its output in its respective
170+
[JSON file](logs/standard/get_block_number_by_timestamp.json):
171+
172+
``` json
173+
{
174+
"method": "get_block_number_by_timestamp",
175+
"module": "blocks",
176+
"kwargs": {
177+
"timestamp": "1578638524",
178+
"closest": "before"
179+
},
180+
"log_timestamp": "2020-10-28-12:34:44",
181+
"res": "9251482"
182+
}
183+
```
184+
185+
where `kwargs` refer to the required named arguments and `res` refers to the expected result if you were to run:
186+
187+
``` python
188+
eth.get_block_number_by_timestamp(timestamp="1578638524", closest="before")
189+
190+
> '9251482'
191+
```
192+
193+
**Disclaimer**: Those examples blindly use the arguments originally showcased
194+
[here](https://api.polygonscan.com/apis) and the selected wallets/contracts
195+
do not reflect any personal preference. You should refer to the same source for additional
196+
information regarding specific argument values.
197+
198+
## Issues
199+
200+
For problems regarding installing or using the package please open an
201+
[issue](https://github.com/tarsil/polygonscan-python/issues).
202+
Kindly avoid disclosing potentially sensitive information such as your API keys or your wallet addresses.
203+
204+
Feel free to leave a :star: if you found this package useful.
205+
206+
___
207+
208+
Powered by [polygonscan.com APIs](https://polygonscan.com/apis).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"method": "get_acc_balance_by_token_and_contract_address",
3+
"module": "tokens",
4+
"kwargs": {
5+
"contract_address": "0x57d90b64a1a57749b0f932f1a3395792e12e7055",
6+
"address": "0xe04f27eb70e025b78871a2ad7eabe85e61212761"
7+
},
8+
"log_timestamp": "2021-09-20-02:15:31",
9+
"res": "0"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"method": "get_block_number_by_timestamp",
3+
"module": "blocks",
4+
"kwargs": {
5+
"timestamp": "1578638524",
6+
"closest": "before"
7+
},
8+
"log_timestamp": "2021-09-20-02:15:19",
9+
"res": "Error! No closest block found"
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"method": "get_block_reward_by_block_number",
3+
"module": "blocks",
4+
"kwargs": {
5+
"block_no": "2165403"
6+
},
7+
"log_timestamp": "2021-09-20-02:15:18",
8+
"res": {
9+
"blockNumber": "2165403",
10+
"timeStamp": "1595322344",
11+
"blockMiner": "0x0375b2fc7140977c9c76d45421564e354ed42277",
12+
"blockReward": "0",
13+
"uncles": [],
14+
"uncleInclusionReward": "0"
15+
}
16+
}

logs/standard/get_contract_abi.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"method": "get_contract_abi",
3+
"module": "contracts",
4+
"kwargs": {
5+
"address": "0x614389eaae0a6821dc49062d56bda3d9d45fa2ff"
6+
},
7+
"log_timestamp": "2020-10-28-12:34:45",
8+
"res": "[{\"inputs\": [{\"internalType\": \"address\", \"name\": \"_proxyTo\", \"type\": \"address\"}], \"stateMutability\": \"nonpayable\", \"type\": \"constructor\"}, {\"anonymous\": false, \"inputs\": [{\"indexed\": false, \"internalType\": \"address\", \"name\": \"_new\", \"type\": \"address\"}, {\"indexed\": false, \"internalType\": \"address\", \"name\": \"_old\", \"type\": \"address\"}], \"name\": \"ProxyOwnerUpdate\", \"type\": \"event\"}, {\"anonymous\": false, \"inputs\": [{\"indexed\": true, \"internalType\": \"address\", \"name\": \"_new\", \"type\": \"address\"}, {\"indexed\": true, \"internalType\": \"address\", \"name\": \"_old\", \"type\": \"address\"}], \"name\": \"ProxyUpdated\", \"type\": \"event\"}, {\"stateMutability\": \"payable\", \"type\": \"fallback\"}, {\"inputs\": [], \"name\": \"implementation\", \"outputs\": [{\"internalType\": \"address\", \"name\": \"\", \"type\": \"address\"}], \"stateMutability\": \"view\", \"type\": \"function\"}, {\"inputs\": [], \"name\": \"proxyOwner\", \"outputs\": [{\"internalType\": \"address\", \"name\": \"\", \"type\": \"address\"}], \"stateMutability\": \"view\", \"type\": \"function\"}, {\"inputs\": [], \"name\": \"proxyType\", \"outputs\": [{\"internalType\": \"uint256\", \"name\": \"proxyTypeId\", \"type\": \"uint256\"}], \"stateMutability\": \"pure\", \"type\": \"function\"}, {\"inputs\": [{\"internalType\": \"address\", \"name\": \"newOwner\", \"type\": \"address\"}], \"name\": \"transferProxyOwnership\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\"}, {\"inputs\": [{\"internalType\": \"address\", \"name\": \"_newProxyTo\", \"type\": \"address\"}, {\"internalType\": \"bytes\", \"name\": \"data\", \"type\": \"bytes\"}], \"name\": \"updateAndCall\", \"outputs\": [], \"stateMutability\": \"payable\", \"type\": \"function\"}, {\"inputs\": [{\"internalType\": \"address\", \"name\": \"_newProxyTo\", \"type\": \"address\"}], \"name\": \"updateImplementation\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\"}, {\"stateMutability\": \"payable\", \"type\": \"receive\"}]"
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"method": "get_contract_execution_status",
3+
"module": "transactions",
4+
"kwargs": {
5+
"txhash": "0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a"
6+
},
7+
"log_timestamp": "2021-09-20-02:15:32",
8+
"res": {
9+
"isError": "0",
10+
"errDescription": ""
11+
}
12+
}

0 commit comments

Comments
 (0)