shadowPaySDK 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shadowPaySDK/__init__.py +2 -0
- shadowPaySDK/interface/__init__.py +0 -0
- shadowPaySDK/interface/erc20.py +102 -0
- shadowPaySDK/interface/erc721.py +66 -0
- shadowpaysdk-0.1.0.dist-info/METADATA +35 -0
- shadowpaysdk-0.1.0.dist-info/RECORD +9 -0
- shadowpaysdk-0.1.0.dist-info/WHEEL +5 -0
- shadowpaysdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- shadowpaysdk-0.1.0.dist-info/top_level.txt +1 -0
shadowPaySDK/__init__.py
ADDED
File without changes
|
@@ -0,0 +1,102 @@
|
|
1
|
+
from web3 import Web3
|
2
|
+
import json
|
3
|
+
from typing import Union, Optional
|
4
|
+
|
5
|
+
ERC20_ABI = json.loads("""[
|
6
|
+
{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"type":"function"},
|
7
|
+
{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"type":"function"},
|
8
|
+
{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},
|
9
|
+
{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
10
|
+
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
11
|
+
{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"type":"function"},
|
12
|
+
{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"type":"function"},
|
13
|
+
{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
14
|
+
{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"type":"function"}
|
15
|
+
]""")
|
16
|
+
|
17
|
+
|
18
|
+
class ERC20Token:
|
19
|
+
def __init__(self, web3: Web3, token: str, explorer: Optional[str] = None):
|
20
|
+
self.web3 = web3
|
21
|
+
self.explorer = explorer
|
22
|
+
self.address = Web3.to_checksum_address(token)
|
23
|
+
self.contract = web3.eth.contract(address=self.address, abi=ERC20_ABI)
|
24
|
+
|
25
|
+
def _format_tx(self, tx_hash: str) -> str:
|
26
|
+
if self.explorer:
|
27
|
+
return f"{self.explorer.rstrip('/')}/tx/{tx_hash}"
|
28
|
+
return tx_hash
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def get_decimals(self) -> int:
|
33
|
+
return self.contract.functions.decimals().call()
|
34
|
+
|
35
|
+
def get_symbol(self) -> str:
|
36
|
+
return self.contract.functions.symbol().call()
|
37
|
+
|
38
|
+
def get_balance(self, wallet_address: str) -> float:
|
39
|
+
raw_balance = self.contract.functions.balanceOf(
|
40
|
+
Web3.to_checksum_address(wallet_address)
|
41
|
+
).call()
|
42
|
+
return raw_balance / (10 ** self.get_decimals())
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
def allowance(self, owner: str, spender: str) -> float:
|
47
|
+
raw = self.contract.functions.allowance(
|
48
|
+
Web3.to_checksum_address(owner),
|
49
|
+
Web3.to_checksum_address(spender)
|
50
|
+
).call()
|
51
|
+
return raw / (10 ** self.get_decimals())
|
52
|
+
|
53
|
+
def ensure_allowance(self, private_key: str, spender: str, amount: float) -> Union[bool, str]:
|
54
|
+
account = self.web3.eth.account.from_key(private_key)
|
55
|
+
current_allowance = self.allowance(account.address, spender)
|
56
|
+
if current_allowance >= amount:
|
57
|
+
return True
|
58
|
+
return self.approve(private_key, spender, amount)
|
59
|
+
|
60
|
+
def transfer(self, private_key: str, to: str, amount: float) -> str:
|
61
|
+
account = self.web3.eth.account.from_key(private_key)
|
62
|
+
decimals = self.get_decimals()
|
63
|
+
value = int(amount * (10 ** decimals))
|
64
|
+
|
65
|
+
txn = self.contract.functions.transfer(
|
66
|
+
Web3.to_checksum_address(to),
|
67
|
+
value
|
68
|
+
).build_transaction({
|
69
|
+
'from': account.address,
|
70
|
+
'nonce': self.web3.eth.get_transaction_count(account.address),
|
71
|
+
'gas': 100_000,
|
72
|
+
'gasPrice': self.web3.to_wei('5', 'gwei'),
|
73
|
+
})
|
74
|
+
|
75
|
+
signed = self.web3.eth.account.sign_transaction(txn, private_key)
|
76
|
+
tx_hash = self.web3.eth.send_raw_transaction(signed.raw_transaction)
|
77
|
+
return self._format_tx(self.web3.to_hex(tx_hash))
|
78
|
+
|
79
|
+
def approve(self, private_key: str, spender: str, amount: float) -> str:
|
80
|
+
account = self.web3.eth.account.from_key(private_key)
|
81
|
+
decimals = self.get_decimals()
|
82
|
+
value = int(amount * (10 ** decimals))
|
83
|
+
|
84
|
+
txn = self.contract.functions.approve(
|
85
|
+
Web3.to_checksum_address(spender),
|
86
|
+
value
|
87
|
+
).build_transaction({
|
88
|
+
'from': account.address,
|
89
|
+
'nonce': self.web3.eth.get_transaction_count(account.address),
|
90
|
+
'gas': 100_000,
|
91
|
+
'gasPrice': self.web3.to_wei('5', 'gwei'),
|
92
|
+
})
|
93
|
+
|
94
|
+
signed = self.web3.eth.account.sign_transaction(txn, private_key)
|
95
|
+
tx_hash = self.web3.eth.send_raw_transaction(signed.raw_transaction)
|
96
|
+
return self._format_tx(self.web3.to_hex(tx_hash))
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
from web3 import Web3
|
2
|
+
import json
|
3
|
+
from typing import Optional, Union
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
ERC721_ABI = json.loads("""[
|
8
|
+
{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"owner","type":"address"}],"type":"function"},
|
9
|
+
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},
|
10
|
+
{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"uri","type":"string"}],"type":"function"},
|
11
|
+
{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transfer","outputs":[],"type":"function"},
|
12
|
+
{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"type":"function"},
|
13
|
+
{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"approved","type":"address"}],"type":"function"}
|
14
|
+
]""")
|
15
|
+
|
16
|
+
class ERC721Token:
|
17
|
+
def __init__(self, web3: Web3, address: str):
|
18
|
+
self.web3 = web3
|
19
|
+
self.address = Web3.to_checksum_address(address)
|
20
|
+
self.contract = self.web3.eth.contract(address=self.address, abi=ERC721_ABI)
|
21
|
+
|
22
|
+
def owner_of(self, token_id: int) -> str:
|
23
|
+
return self.contract.functions.ownerOf(token_id).call()
|
24
|
+
|
25
|
+
def balance_of(self, owner: Union[str, bytes]) -> int:
|
26
|
+
return self.contract.functions.balanceOf(Web3.to_checksum_address(owner)).call()
|
27
|
+
|
28
|
+
def token_uri(self, token_id: int) -> str:
|
29
|
+
return self.contract.functions.tokenURI(token_id).call()
|
30
|
+
|
31
|
+
def get_approved(self, token_id: int) -> str:
|
32
|
+
return self.contract.functions.getApproved(token_id).call()
|
33
|
+
|
34
|
+
def approve(self, private_key: str, to: str, token_id: int) -> str:
|
35
|
+
account = self.web3.eth.account.from_key(private_key)
|
36
|
+
|
37
|
+
txn = self.contract.functions.approve(
|
38
|
+
Web3.to_checksum_address(to),
|
39
|
+
token_id
|
40
|
+
).build_transaction({
|
41
|
+
'from': account.address,
|
42
|
+
'nonce': self.web3.eth.get_transaction_count(account.address),
|
43
|
+
'gas': 100_000,
|
44
|
+
'gasPrice': self.web3.to_wei('5', 'gwei')
|
45
|
+
})
|
46
|
+
|
47
|
+
signed = self.web3.eth.account.sign_transaction(txn, private_key)
|
48
|
+
tx_hash = self.web3.eth.send_raw_transaction(signed.rawTransaction)
|
49
|
+
return self.web3.to_hex(tx_hash)
|
50
|
+
|
51
|
+
def transfer(self, private_key: str, to: str, token_id: int) -> str:
|
52
|
+
account = self.web3.eth.account.from_key(private_key)
|
53
|
+
|
54
|
+
txn = self.contract.functions.transfer(
|
55
|
+
Web3.to_checksum_address(to),
|
56
|
+
token_id
|
57
|
+
).build_transaction({
|
58
|
+
'from': account.address,
|
59
|
+
'nonce': self.web3.eth.get_transaction_count(account.address),
|
60
|
+
'gas': 150_000,
|
61
|
+
'gasPrice': self.web3.to_wei('5', 'gwei')
|
62
|
+
})
|
63
|
+
|
64
|
+
signed = self.web3.eth.account.sign_transaction(txn, private_key)
|
65
|
+
tx_hash = self.web3.eth.send_raw_transaction(signed.rawTransaction)
|
66
|
+
return self.web3.to_hex(tx_hash)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: shadowPaySDK
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction
|
5
|
+
Author: dazarius_
|
6
|
+
Author-email: your@email.com
|
7
|
+
License: MIT
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.9
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: web3>=6.0.0
|
15
|
+
Requires-Dist: requests>=2.28.0
|
16
|
+
Requires-Dist: solana>=0.35.0
|
17
|
+
Dynamic: author
|
18
|
+
Dynamic: author-email
|
19
|
+
Dynamic: classifier
|
20
|
+
Dynamic: description
|
21
|
+
Dynamic: description-content-type
|
22
|
+
Dynamic: license
|
23
|
+
Dynamic: license-file
|
24
|
+
Dynamic: requires-dist
|
25
|
+
Dynamic: requires-python
|
26
|
+
Dynamic: summary
|
27
|
+
|
28
|
+
# shadowPayS
|
29
|
+
|
30
|
+
```bash
|
31
|
+
pip3 install shadowPaySDK
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
shadowPaySDK/__init__.py,sha256=SVD6oWKXG4CIsPAT4y1AWpqueA2WXXwF1fjFPOB_s0s,79
|
2
|
+
shadowPaySDK/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
shadowPaySDK/interface/erc20.py,sha256=0aJp1FFXP2lb7gVOUFdxGAkiQASTnEcUFpZAcAw9O5c,4517
|
4
|
+
shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
|
5
|
+
shadowpaysdk-0.1.0.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
|
6
|
+
shadowpaysdk-0.1.0.dist-info/METADATA,sha256=_mwAAugZ5gQrXMAQ4Tvq8oe5QFg5HnQS1oWNuWySRjA,784
|
7
|
+
shadowpaysdk-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
shadowpaysdk-0.1.0.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
|
9
|
+
shadowpaysdk-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 dazarius_
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
shadowPaySDK
|