|
| 1 | +# NFTLabs Python SDK |
| 2 | + |
| 3 | +PyPi package found [here](https://pypi.org/project/nftlabs-sdk). |
| 4 | + |
| 5 | +## Package Structure |
| 6 | + |
| 7 | +``` |
| 8 | +nftlabs |
| 9 | +├── abi // contains autogenerated ABI contract wrappers |
| 10 | +├── errors // commonly thrown errors |
| 11 | +├── modules // NFT, Currency, Marketplace, Pack, Collection, etc modules |
| 12 | +├── options // Options classes used throughout the SDK |
| 13 | +├── sdk.py // NftlabsSdk class, wrapper for the entire package |
| 14 | +├── storage // Distributed file storage helper classes |
| 15 | +└── types // Types consumed by some of the methods exposed in the modules |
| 16 | +``` |
| 17 | + |
| 18 | +## Calling the modules |
| 19 | + |
| 20 | +You can call the NFTLabs modules by instantiating an SDK object and fetching the module with your contract address |
| 21 | +like this: |
| 22 | + |
| 23 | +```python |
| 24 | +import os |
| 25 | +import nftlabs.options |
| 26 | +from nftlabs import NftlabsSdk |
| 27 | + |
| 28 | +options = nftlabs.options.SdkOptions() |
| 29 | +sdk = NftlabsSdk(options, "https://rpc-mumbai.maticvigil.com") # polygon testnet as an example |
| 30 | + |
| 31 | +# Assumes your private key is assigned to the `PKEY` environment variable |
| 32 | +sdk.set_private_key(os.getenv("PKEY")) |
| 33 | + |
| 34 | +# Put your NFT contract address here if you want to mint your own NFTs! |
| 35 | +nft_module = sdk.get_nft_module("0xbDfF8fb43688fB4D2184DF8029A7238ac1413A24") |
| 36 | +print(nft_module.total_supply()) |
| 37 | +``` |
| 38 | + |
| 39 | +## Development |
| 40 | + |
| 41 | +### Generating ABI wrappers |
| 42 | + |
| 43 | +The `abi` package contains autogenerated code compiled by the |
| 44 | +0xchain `abi-gen` tool found [here](https://www.npmjs.com/package/@0x/abi-gen). |
| 45 | + |
| 46 | +Our protocols are developer at [this repo](https://github.com/nftlabs/nftlabs-protocols). |
| 47 | + |
| 48 | +Install the `abi-gen` cli tool and use it to compile abi wrappers like this: |
| 49 | + |
| 50 | +```bash |
| 51 | +$ # assumes you have the nftlabs-protocols repo cloned in the parent directory |
| 52 | +$ abi-gen --language Python -o nftlabs/abi --abis ../nftlabs-protocols/abi/NFT.json |
| 53 | +``` |
| 54 | + |
| 55 | +Anytime there are ABI contract changes, you should regenerate the abi wrappers. |
0 commit comments