Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 20d1cfd

Browse files
authored
Fix sdk.getContract and erc20, erc721, and erc1155 namespaces (#121)
* Fix sdk.getContract and erc20, erc721, and erc1155 namespaces * Add publishing instructions
1 parent b375282 commit 20d1cfd

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ Once you have run the initialization step, you can run the following to run all
110110
$ make test
111111
```
112112

113+
### Publishing the Package
114+
115+
To make a build & publish the package, you need to have a `pypi` account with permission to edit the `thirdweb-sdk` pypi package. You can authenticate your pypi account with poetry with the following command:
116+
117+
```bash
118+
poetry config pypi-token.pypi pypi-token-here
119+
```
120+
121+
Then, you can build and release a prerelease version with the following command:
122+
123+
```bash
124+
make publish
125+
```
126+
113127
### Code Style Setup
114128

115129
Make sure you have `mypy`, `pylint`, and `black` installed (all included in the dev dependencies with `poetry install`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages = [
66
{include = "thirdweb"},
77
]
88
readme = "README.md"
9-
version = "3.0.1"
9+
version = "3.0.2a1"
1010

1111
[tool.poetry.dependencies]
1212
python = ">=3.7.1"

thirdweb/common/feature_detection.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def extract_minimal_proxy_implementation_address(bytecode: HexBytes) -> str:
5656

5757

5858
def resolve_contract_uri_from_address(address: str, provider: Web3) -> str:
59-
bytecode = provider.eth.get_code(address)
59+
bytecode = provider.eth.get_code(provider.toChecksumAddress(address))
6060
if bytecode.hex() == "0x":
6161
raise Exception(f"Contract at '{address}' does not exist")
6262

@@ -68,6 +68,21 @@ def resolve_contract_uri_from_address(address: str, provider: Web3) -> str:
6868
except:
6969
pass
7070

71+
try:
72+
proxy_storage = provider.eth.get_storage_at(
73+
provider.toChecksumAddress(address),
74+
# hex: 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
75+
24440054405305269366569402256811496959409073762505157381672968839269610695612
76+
)
77+
implementation_address = "0x" + proxy_storage.hex().replace("0x", "").lstrip("0")
78+
if implementation_address != "0x":
79+
return resolve_contract_uri_from_address(
80+
implementation_address,
81+
provider,
82+
)
83+
except:
84+
pass
85+
7186
return extract_ipfs_hash_from_bytecode(bytecode)
7287

7388

thirdweb/contracts/custom.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from thirdweb.abi.i_token_erc1155 import ITokenERC1155
77
from thirdweb.abi.i_token_erc20 import ITokenERC20
88
from thirdweb.abi.i_token_erc721 import ITokenERC721
9+
from thirdweb.abi.token_erc1155 import TokenERC1155
10+
from thirdweb.abi.token_erc20 import TokenERC20
911
from thirdweb.abi.token_erc721 import TokenERC721
1012
from thirdweb.common.error import NoSignerException
1113
from thirdweb.common.feature_detection import matches_interface
@@ -97,9 +99,9 @@ def __init__(
9799
self.sales = self._detect_primary_sales()
98100
self.platform_fee = self._detect_platform_fee()
99101

100-
self.token = self._detect_erc_20()
101-
self.nft = self._detect_erc_721()
102-
self.edition = self._detect_erc_1155()
102+
self.erc20 = self._detect_erc_20()
103+
self.erc721 = self._detect_erc_721()
104+
self.erc1155 = self._detect_erc_1155()
103105

104106
def call(self, fn: str, *args) -> Any:
105107
func = cast(ContractFunction, getattr(self.functions, fn, None))
@@ -190,26 +192,26 @@ def _detect_platform_fee(self):
190192
return None
191193

192194
def _detect_erc_20(self):
193-
interface_to_match = self._get_interface_functions(ITokenERC20.abi())
195+
interface_to_match = self._get_interface_functions(TokenERC20.abi())
194196

195197
if matches_interface(self.functions, interface_to_match):
196-
contract_wrapper = self._get_contract_wrapper(ITokenERC20)
198+
contract_wrapper = self._get_contract_wrapper(TokenERC20)
197199
return ERC20(contract_wrapper, self._storage)
198200
return None
199201

200202
def _detect_erc_721(self):
201-
interface_to_match = self._get_interface_functions(ITokenERC721.abi())
203+
interface_to_match = self._get_interface_functions(TokenERC721.abi())
202204

203205
if matches_interface(self.functions, interface_to_match):
204-
contract_wrapper = self._get_contract_wrapper(ITokenERC721)
206+
contract_wrapper = self._get_contract_wrapper(TokenERC721)
205207
return ERC721(contract_wrapper, self._storage)
206208
return None
207209

208210
def _detect_erc_1155(self):
209-
interface_to_match = self._get_interface_functions(ITokenERC1155.abi())
211+
interface_to_match = self._get_interface_functions(TokenERC1155.abi())
210212

211213
if matches_interface(self.functions, interface_to_match):
212-
contract_wrapper = self._get_contract_wrapper(ITokenERC1155)
214+
contract_wrapper = self._get_contract_wrapper(TokenERC1155)
213215
return ERC1155(contract_wrapper, self._storage)
214216
return None
215217

0 commit comments

Comments
 (0)