Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0c45767

Browse files
Addition of Transactions module
1 parent 5db2cdf commit 0c45767

File tree

9 files changed

+241
-1
lines changed

9 files changed

+241
-1
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Currently, only the following Etherscan.io API modules are available:
3535
- tokens
3636
- proxies
3737
- blocks
38+
- transactions
3839

3940
The remaining available modules provided by Etherscan.io will be added eventually...
4041

‎etherscan/transactions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .client import Client
2+
3+
4+
class Transactions(Client):
5+
def __init__(self, api_key='YourApiKeyToken'):
6+
Client.__init__(self, address='', api_key=api_key)
7+
self.url_dict[self.MODULE] = 'transaction'
8+
9+
def get_status(self, tx_hash: str):
10+
self.url_dict[self.ACTION] = 'getstatus'
11+
self.url_dict[self.TXHASH] = tx_hash
12+
self.build_url()
13+
req = self.connect()
14+
return req['result']
15+
16+
def get_tx_receipt_status(self, tx_hash: str):
17+
self.url_dict[self.ACTION] = 'gettxreceiptstatus'
18+
self.url_dict[self.TXHASH] = tx_hash
19+
self.build_url()
20+
req = self.connect()
21+
return req['result']

‎examples/blocks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'Corey Petty'
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%load_ext autoreload\n",
10+
"%autoreload 2\n",
11+
"import etherscan.transactions as transactions\n",
12+
"import json"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"## Import our api_key"
20+
]
21+
},
22+
{
23+
"cell_type": "markdown",
24+
"metadata": {},
25+
"source": [
26+
"The JSON keyfile being read in has only one line in the format:\n",
27+
" \n",
28+
" {\"key\" : \"YourApiKey\" }"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 2,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"with open('../../api_key.json', mode='r') as key_file:\n",
38+
" key = json.loads(key_file.read())['key']"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"## Set up API"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 8,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"api = transactions.Transactions(api_key=key)"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"## Get the transaction status and transaction receipt status"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": 9,
67+
"metadata": {
68+
"scrolled": false
69+
},
70+
"outputs": [],
71+
"source": [
72+
"TX_HASH = '0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a'\n",
73+
"status = api.get_status(tx_hash=TX_HASH)"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 10,
79+
"metadata": {},
80+
"outputs": [
81+
{
82+
"data": {
83+
"text/plain": [
84+
"{'isError': '1', 'errDescription': 'Bad jump destination'}"
85+
]
86+
},
87+
"execution_count": 10,
88+
"metadata": {},
89+
"output_type": "execute_result"
90+
}
91+
],
92+
"source": [
93+
"status"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": 11,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"TX_HASH = '0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76'\n",
103+
"receipt_status = api.get_tx_receipt_status(tx_hash=TX_HASH)"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 12,
109+
"metadata": {},
110+
"outputs": [
111+
{
112+
"data": {
113+
"text/plain": [
114+
"{'status': '1'}"
115+
]
116+
},
117+
"execution_count": 12,
118+
"metadata": {},
119+
"output_type": "execute_result"
120+
}
121+
],
122+
"source": [
123+
"receipt_status"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": null,
129+
"metadata": {},
130+
"outputs": [],
131+
"source": []
132+
}
133+
],
134+
"metadata": {
135+
"kernelspec": {
136+
"display_name": "Python 3",
137+
"language": "python",
138+
"name": "python3"
139+
},
140+
"language_info": {
141+
"codemirror_mode": {
142+
"name": "ipython",
143+
"version": 3
144+
},
145+
"file_extension": ".py",
146+
"mimetype": "text/x-python",
147+
"name": "python",
148+
"nbconvert_exporter": "python",
149+
"pygments_lexer": "ipython3",
150+
"version": "3.7.0"
151+
},
152+
"latex_envs": {
153+
"bibliofile": "biblio.bib",
154+
"cite_by": "apalike",
155+
"current_citInitial": 1,
156+
"eqLabelWithNumbers": true,
157+
"eqNumInitial": 0
158+
},
159+
"toc": {
160+
"nav_menu": {
161+
"height": "121px",
162+
"width": "252px"
163+
},
164+
"navigate_menu": true,
165+
"number_sections": true,
166+
"sideBar": true,
167+
"threshold": 4,
168+
"toc_cell": false,
169+
"toc_section_display": "block",
170+
"toc_window_display": false
171+
}
172+
},
173+
"nbformat": 4,
174+
"nbformat_minor": 2
175+
}

‎examples/transactions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'Corey Petty'

‎examples/transactions/get_status.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from etherscan.transactions import Transactions
2+
import json
3+
4+
with open('../../api_key.json', mode='r') as key_file:
5+
key = json.loads(key_file.read())['key']
6+
7+
TX_HASH = '0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a'
8+
api = Transactions(api_key=key)
9+
status = api.get_status(tx_hash=TX_HASH)
10+
print(status)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from etherscan.transactions import Transactions
2+
import json
3+
4+
with open('../../api_key.json', mode='r') as key_file:
5+
key = json.loads(key_file.read())['key']
6+
7+
TX_HASH = '0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76'
8+
api = Transactions(api_key=key)
9+
receipt_status = api.get_tx_receipt_status(tx_hash=TX_HASH)
10+
print(receipt_status)

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name='py_etherscan_api',
55
version='0.8.0',
66
packages=['examples', 'examples.stats', 'examples.tokens',
7-
'examples.accounts', 'examples.blocks', 'etherscan'],
7+
'examples.accounts', 'examples.blocks', 'examples.transactions', 'etherscan'],
88
url='https://github.com/corpetty/py-etherscan-api',
99
license='MIT',
1010
author='coreypetty',

‎tests/test_transactions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
3+
from etherscan.transactions import Transactions
4+
5+
API_KEY = 'YourAPIkey'
6+
TX_HASH_1 = '0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a'
7+
TX_HASH_2 = '0x513c1ba0bebf66436b5fed86ab668452b7805593c05073eb2d51d3a52f480a76'
8+
ERROR_STRING = 'Bad jump destination'
9+
10+
class TransactionsTestCase(unittest.TestCase):
11+
12+
def test_get_status(self):
13+
api = Transactions(api_key=(API_KEY))
14+
status = api.get_status(TX_HASH_1)
15+
self.assertEqual(status['isError'], '1')
16+
self.assertEqual(status['errDescription'], ERROR_STRING)
17+
18+
def test_get_tx_receipt_status(self):
19+
api = Transactions(api_key=(API_KEY))
20+
receipt_status = api.get_tx_receipt_status(TX_HASH_2)
21+
self.assertEqual(receipt_status['status'], '1')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /