Thanks to visit codestin.com
Credit goes to github.com

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

Commit d0d2f24

Browse files
authored
Add support for multiwrap contract (#98)
* Add multiwrap ABI * Add multiwrap contract implementation * Update exported types * Update docs and snippets * Update get_owned_token_ids * Update multiwrap docs * Move get_owned functions to top level * Fix get all for multiwrap * Update version
1 parent a57ce58 commit d0d2f24

Some content is hidden

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

56 files changed

+28372
-6278
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ abi:
2828
abi-gen --language Python -o thirdweb/abi --abis abi/IERC1155.json && mv thirdweb/abi/ierc1155/__init__.py thirdweb/abi/ierc1155.py && rm -rf thirdweb/abi/ierc1155
2929
abi-gen --language Python -o thirdweb/abi --abis abi/DropERC721.json && mv thirdweb/abi/drop_erc721/__init__.py thirdweb/abi/drop_erc721.py && rm -rf thirdweb/abi/drop_erc721
3030
abi-gen --language Python -o thirdweb/abi --abis abi/DropERC1155.json && mv thirdweb/abi/drop_erc1155/__init__.py thirdweb/abi/drop_erc1155.py && rm -rf thirdweb/abi/drop_erc1155
31+
abi-gen --language Python -o thirdweb/abi --abis abi/Multiwrap.json && mv thirdweb/abi/multiwrap/__init__.py thirdweb/abi/multiwrap.py && rm -rf thirdweb/abi/multiwrap
3132

3233
abi-gen --language Python -o thirdweb/abi --abis abi/SignatureMintERC20.json && mv thirdweb/abi/signature_mint_erc20/__init__.py thirdweb/abi/signature_mint_erc20.py && rm -rf thirdweb/abi/signature_mint_erc20
3334
abi-gen --language Python -o thirdweb/abi --abis abi/SignatureMintERC721.json && mv thirdweb/abi/signature_mint_erc721/__init__.py thirdweb/abi/signature_mint_erc721.py && rm -rf thirdweb/abi/signature_mint_erc721
@@ -45,6 +46,7 @@ abi:
4546
abi-gen --language Python -o thirdweb/abi --abis abi/IPlatformFee.json && mv thirdweb/abi/i_platform_fee/__init__.py thirdweb/abi/i_platform_fee.py && rm -rf thirdweb/abi/i_platform_fee
4647
abi-gen --language Python -o thirdweb/abi --abis abi/IRoyalty.json && mv thirdweb/abi/i_royalty/__init__.py thirdweb/abi/i_royalty.py && rm -rf thirdweb/abi/i_royalty
4748

49+
4850
snippets:
4951
poetry run python3 scripts/generate_snippets.py
5052

docs/docs/contract-deployer.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ def deploy_edition_drop(metadata: EditionDropContractMetadata) -> str
7070

7171
Deploy an Edition Drop contract
7272

73+
<a id="core.classes.contract_deployer.ContractDeployer.deploy_multiwrap"></a>
74+
75+
#### deploy\_multiwrap
76+
77+
```python
78+
def deploy_multiwrap(metadata: MultiwrapContractMetadata) -> str
79+
```
80+
81+
Deploy a Multiwrap contract
82+

docs/docs/erc721.md

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,47 +71,6 @@ Get the total number of NFTs minted by this contract
7171

7272
the total number of NFTs minted by this contract
7373

74-
<a id="core.classes.erc_721.ERC721.get_owned"></a>
75-
76-
#### get\_owned
77-
78-
```python
79-
def get_owned(address: str = "") -> List[NFTMetadataOwner]
80-
```
81-
82-
Get the metadata of all tokens owned by a specific address
83-
84-
```python
85-
nfts = contract.get_owned("{{wallet_address}}")
86-
print(nfts)
87-
```
88-
89-
**Arguments**:
90-
91-
- `address`: the address to get the metadata for
92-
93-
**Returns**:
94-
95-
the metadata of all tokens owned by the address
96-
97-
<a id="core.classes.erc_721.ERC721.get_owned_token_ids"></a>
98-
99-
#### get\_owned\_token\_ids
100-
101-
```python
102-
def get_owned_token_ids(address: str = "") -> List[int]
103-
```
104-
105-
Get the token IDs owned by a specific address
106-
107-
**Arguments**:
108-
109-
- `address`: the address to get the token IDs for
110-
111-
**Returns**:
112-
113-
the token IDs owned by the address
114-
11574
<a id="core.classes.erc_721.ERC721.owner_of"></a>
11675

11776
#### owner\_of
@@ -271,5 +230,26 @@ Set the approval of an operator for all operations of a specific address's asset
271230

272231
**Returns**:
273232

274-
transaction receipt of the approval setting
233+
transaction receipt of the approval
234+
235+
<a id="core.classes.erc_721.ERC721.set_approval_for_token"></a>
236+
237+
#### set\_approval\_for\_token
238+
239+
```python
240+
def set_approval_for_token(operator: str, token_id: int) -> TxReceipt
241+
```
242+
243+
Approve an operator for the NFT owner, which allows the operator to call transferFrom
244+
245+
or safeTransferFrom for the specified token.
246+
247+
**Arguments**:
248+
249+
- `operator`: the address of the operator to set the approval for
250+
- `token_id`: the specific token ID to set the approval for
251+
252+
**Returns**:
253+
254+
transaction receipt of the approval
275255

docs/docs/multiwrap.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<a id="contracts.multiwrap"></a>
2+
3+
# contracts.multiwrap
4+
5+
<a id="contracts.multiwrap.Multiwrap"></a>
6+
7+
## Multiwrap Objects
8+
9+
```python
10+
class Multiwrap(ERC721[MultiwrapABI])
11+
```
12+
13+
Multiwrap lets you wrap any number of ERC20, ERC721, or ERC1155 tokens into
14+
a single wrapped token bundle.
15+
16+
```python
17+
from thirdweb import ThirdwebSDK
18+
19+
# You can customize this to a supported network or your own RPC URL
20+
network = "mumbai"
21+
22+
# Now we can create a new instance of the SDK
23+
sdk = ThirdwebSDK(network)
24+
25+
# If you want to send transactions, you can instantiate the SDK with a private key instead:
26+
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
27+
28+
contract = sdk.get_multiwrap("{{contract_address}}")
29+
```
30+
31+
<a id="contracts.multiwrap.Multiwrap.get_wrapped_contents"></a>
32+
33+
#### get\_wrapped\_contents
34+
35+
```python
36+
def get_wrapped_contents(wrapped_token_id: int) -> WrappedTokens
37+
```
38+
39+
Get the contents of a wrapped token bundle
40+
41+
**Arguments**:
42+
43+
- `wrapped_token_id`: The ID of the wrapped token to get the contents of
44+
45+
**Returns**:
46+
47+
The contents of the wrapped token bundle
48+
```python
49+
token_id = 0
50+
contents = contract.get_wrapped_contents(token_id)
51+
print(contents.erc20_tokens)
52+
print(contents.erc721_tokens)
53+
print(contents.erc1155_tokens)
54+
```
55+
56+
<a id="contracts.multiwrap.Multiwrap.wrap"></a>
57+
58+
#### wrap
59+
60+
```python
61+
def wrap(
62+
contents: TokensToWrap,
63+
wrapped_token_metadata: Union[str, NFTMetadataInput],
64+
recipient_address: Optional[str] = None
65+
) -> TxResultWithId[NFTMetadataOwner]
66+
```
67+
68+
Wrap any number of ERC20, ERC721, or ERC1155 tokens into a single wrapped token
69+
70+
**Arguments**:
71+
72+
- `contents`: The tokens to wrap into a single wrapped token
73+
- `wrapped_token_metadata`: The metadata to use for the wrapped token
74+
- `recipient_address`: The optional address to send the wrapped token to
75+
76+
**Returns**:
77+
78+
The transaction receipt of the token wrapping
79+
```python
80+
from thirdweb.types import (
81+
TokensToWrap,
82+
ERC20Wrappable,
83+
ERC721Wrappable,
84+
ERC1155Wrappable,
85+
NFTMetadataInput,
86+
)
87+
88+
# Contract setup goes here...
89+
90+
tx = contract.wrap(
91+
TokensToWrap(
92+
erc20_tokens=[
93+
ERC20Wrappable(contract_address="0x...", quantity=0.8),
94+
],
95+
erc721_tokens=[
96+
ERC721Wrappable(contract_address="0x...", token_id=0),
97+
],
98+
erc1155_tokens=[
99+
ERC1155Wrappable(contract_address="0x...", token_id=0, quantity=1),
100+
]
101+
),
102+
NFTMetadataInput(
103+
name="Wrapped NFT",
104+
description="This is a wrapped bundle of tokens and NFTs",
105+
image="ipfs://...",
106+
)
107+
)
108+
109+
print(tx.receipt, tx.id)
110+
```
111+
112+
<a id="contracts.multiwrap.Multiwrap.unwrap"></a>
113+
114+
#### unwrap
115+
116+
```python
117+
def unwrap(wrapped_token_id: int,
118+
recipient_address: Optional[str] = None) -> TxReceipt
119+
```
120+
121+
Unwrap a wrapped token bundle
122+
123+
**Arguments**:
124+
125+
- `wrapped_token_id`: The ID of the wrapped token to unwrap
126+
- `recipient_address`: The optional address to send the unwrapped tokens to
127+
128+
**Returns**:
129+
130+
The transaction receipt of the token unwrapping
131+
```python
132+
tx = contract.unwrap(wrapped_token_id, receipientAddress)
133+
```
134+

docs/docs/nft-collection.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,47 @@ sdk = ThirdwebSDK(network)
2929
contract = sdk.get_nft_collection("{{contract_address}}")
3030
```
3131

32+
<a id="contracts.nft_collection.NFTCollection.get_owned"></a>
33+
34+
#### get\_owned
35+
36+
```python
37+
def get_owned(address: str = "") -> List[NFTMetadataOwner]
38+
```
39+
40+
Get the metadata of all tokens owned by a specific address
41+
42+
```python
43+
nfts = contract.get_owned("{{wallet_address}}")
44+
print(nfts)
45+
```
46+
47+
**Arguments**:
48+
49+
- `address`: the address to get the metadata for
50+
51+
**Returns**:
52+
53+
the metadata of all tokens owned by the address
54+
55+
<a id="contracts.nft_collection.NFTCollection.get_owned_token_ids"></a>
56+
57+
#### get\_owned\_token\_ids
58+
59+
```python
60+
def get_owned_token_ids(address: str = "") -> List[int]
61+
```
62+
63+
Get the token IDs owned by a specific address
64+
65+
**Arguments**:
66+
67+
- `address`: the address to get the token IDs for
68+
69+
**Returns**:
70+
71+
the token IDs owned by the address
72+
3273
<a id="contracts.nft_collection.NFTCollection.mint"></a>
3374

3475
#### mint

docs/docs/nft-drop.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,47 @@ sdk = ThirdwebSDK(network)
2727
contract = sdk.get_nft_drop("{{contract_address}}")
2828
```
2929

30+
<a id="contracts.nft_drop.NFTDrop.get_owned"></a>
31+
32+
#### get\_owned
33+
34+
```python
35+
def get_owned(address: str = "") -> List[NFTMetadataOwner]
36+
```
37+
38+
Get the metadata of all tokens owned by a specific address
39+
40+
```python
41+
nfts = contract.get_owned("{{wallet_address}}")
42+
print(nfts)
43+
```
44+
45+
**Arguments**:
46+
47+
- `address`: the address to get the metadata for
48+
49+
**Returns**:
50+
51+
the metadata of all tokens owned by the address
52+
53+
<a id="contracts.nft_drop.NFTDrop.get_owned_token_ids"></a>
54+
55+
#### get\_owned\_token\_ids
56+
57+
```python
58+
def get_owned_token_ids(address: str = "") -> List[int]
59+
```
60+
61+
Get the token IDs owned by a specific address
62+
63+
**Arguments**:
64+
65+
- `address`: the address to get the token IDs for
66+
67+
**Returns**:
68+
69+
the token IDs owned by the address
70+
3071
<a id="contracts.nft_drop.NFTDrop.get_all_claimed"></a>
3172

3273
#### get\_all\_claimed

docs/docs/sdk.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ Returns an Edition Drop contract SDK instance
140140

141141
Edition Drop contract SDK instance
142142

143+
<a id="core.sdk.ThirdwebSDK.get_multiwrap"></a>
144+
145+
#### get\_multiwrap
146+
147+
```python
148+
def get_multiwrap(address: str) -> Multiwrap
149+
```
150+
151+
Returns a multiwrap contract SDK instance
152+
153+
**Arguments**:
154+
155+
- `address`: address of the multiwrap contract
156+
157+
**Returns**:
158+
159+
multiwrap contract SDK instance
160+
143161
<a id="core.sdk.ThirdwebSDK.get_contract"></a>
144162

145163
#### get\_contract

0 commit comments

Comments
 (0)