forked from rustamg23/IzzyNFTs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.py
93 lines (73 loc) · 3.24 KB
/
lib.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
from solana.rpc.api import Client
from theblockchainapi import TheBlockchainAPIResource, SolanaNetwork
import requests
class SolEnd:
def __init__(self, network='dev'):
if network == 'dev':
self.client = Client("https://api.devnet.solana.com/")
self.network = 'devnet'
elif network == 'main':
self.client = Client("https://solana-mainnet.phantom.tech")
self.network = 'mainnet'
else:
self.client = Client("https://api.devnet.solana.com/")
self.network = 'devnet'
print('This network mode does not exist!')
print(f'You work in {self.network}')
self.addr_to_nick = {}
self.BLOCKCHAIN_API_RESOURCE = TheBlockchainAPIResource(
# you need to create on this site https://dashboard.blockchainapi.com/#contact
api_key_id="9spRKqC0GgLYLpL",
api_secret_key="f573q7V4fMi3abC"
)
self.users_profile = {}
def balance(self, address):
return self.client.get_balance(address)
def price_in_usdt(self):
link_sol = 'https://public-api.solscan.io/market/token/So11111111111111111111111111111111111111112'
res = requests.get(link_sol).json()
return res["priceUsdt"]
def registration(self, pub_key, nickname):
self.addr_to_nick[nickname] = pub_key
return self.addr_to_nick
def get_tokens(self, wallet_address):
if self.network == 'devnet':
link = f'https://api-devnet.solscan.io/account/tokens?address={wallet_address}'
res = requests.get(link).json()['data']
elif self.network == 'mainnet':
link = f'https://public-api.solscan.io/account/tokens?account={wallet_address}'
res = requests.get(link).json()
addr_of_tokens = [tokens['tokenAddress'] for tokens in res]
# for tokens in res:
# addr_of_tokens.append(tokens['tokenAddress'])
return addr_of_tokens
def get_nft_metadata(self, nft_address):
if self.network == 'devnet':
network = SolanaNetwork.DEVNET
elif self.network == 'mainnet':
network = SolanaNetwork.MAINNET_BETA
nft_metadata = self.BLOCKCHAIN_API_RESOURCE.get_nft_metadata(
mint_address=nft_address,
network=network
)
return nft_metadata
def get_uri_token(self, nft_metadata):
uri_token = nft_metadata['data']['uri']
return uri_token
def request_img(self, uri_token):
img = requests.get(uri_token).json()['image']
return img
def request_data(seld, uri_token):
name = requests.get(uri_token).json()["name"]
info = requests.get(uri_token).json()["description"]
res = f'{name} \n{info}' \
f'\n- - - - - - - - - - - - - - - -' \
f' - - - - - - - - - - - - - - - - \n' \
f'price is not set, people can offer bids, or you can set the price now.'
return res
def bid(self, binder: str, holder: str, nft_address: str):
self.users_profile[holder] = {"token": nft_address,
"binder": binder}
if __name__ == "__main__":
address = 'H2hFezqB6JNVUixUMttJogFr3KvhTDX4bLvT8Rq4eJwW'
print(SolEnd().req(address))