-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
131 lines (115 loc) · 4.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Importing system modules
import os
import sys
# Importing third party modules
from dotenv import load_dotenv
from pyfiglet import Figlet
from PyInquirer import Separator, prompt
from termcolor import colored
# Importing thirdweb-sdk
from thirdweb import SdkOptions, ThirdwebSdk
# Defining the main function
def main() -> None:
# Creating the initial figlet
f = Figlet(font='slant')
credit = colored(
' By Arpan Pandey\n', 'blue', attrs=['bold'])
description = colored(
f'A CLI tool to manage your own NFT Collection from the command line via the *thirdweb* platform.', 'cyan')
# Printing the initial figlet with description
print(colored(f.renderText('WEB3 CLI'), 'green'), credit, description, '\n')
# Getting the nft data via a prompt
nft_data = prompt([
{
'type': 'list',
'name': 'module',
'message': 'Select the module you want to use',
'choices': [
Separator('-- Modules --'),
{
'name': 'NFT Collection',
'value': 'nft_collection',
'short': 'NFT Collection'
},
{
'name': 'NFT Bundle',
'value': 'nft_bundle',
'short': 'NFT Bundle'
},
{
'name': 'Currency',
'value': 'currency',
'short': 'Currency'
},
]
},
{
'type': 'input',
'name': 'NFT Smart Contract Address',
'message': 'Enter the NFT Smart Contract Address',
'validate': lambda val: val != ''
},
{
'type': 'input',
'name': 'Network URL',
'message': 'Enter the Network URL',
'default': "https://rinkeby-light.eth.linkpool.io/",
},
{
'type': 'list',
'name': 'Where is the Private Key?',
'message': 'Where is the Private Key?',
'choices': [
Separator('-- Where is the Private Key? --'),
{
'name': 'In the Environment',
'value': 'env'
},
{
'name': 'I will provide it in the next step',
'value': 'next_step'
}
]
},
{
'type': 'password',
'name': 'Private Key',
'message': 'Enter the Private Key',
'when': lambda answers: answers['Where is the Private Key?'] == 'next_step',
'validate': lambda val: val != ''
}
])
# Creating the sdk options or reporting error
try:
network = nft_data['Network URL']
sdk = ThirdwebSdk(SdkOptions(
ipfs_gateway_url='https://cloudflare-ipfs.com/ipfs/'), network)
if nft_data['Where is the Private Key?'] == 'env':
load_dotenv()
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
if PRIVATE_KEY is None:
print(colored(
'No private key found in the environment. make sure it is saved as `PRIVATE_KEY={Your Private Key}` in and `.env` file.', 'red'))
sys.exit(1)
else:
PRIVATE_KEY = nft_data['Private Key']
sdk.set_private_key(PRIVATE_KEY)
except Exception:
print(colored('Error In Data', 'red'))
sys.exit(1)
# Calling the selected module
if nft_data['module'] == 'nft_collection':
nft_module = sdk.get_nft_module(nft_data['NFT Smart Contract Address'])
from modules.collection import nft_collection
nft_collection(nft_module=nft_module)
elif nft_data['module'] == 'currency':
currency_module = sdk.get_currency_module(nft_data['NFT Smart Contract Address'])
from modules.currency import currency
currency(currency_module=currency_module)
elif nft_data['module'] == 'nft_bundle':
print(colored('Support for bundles coming soon', 'blue'))
else:
print(colored('No Module Selected', 'red'))
# Calling the main function
if __name__ == '__main__':
main()