-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib_main.py
70 lines (57 loc) · 2.21 KB
/
lib_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
from solana.rpc.api import Client
from theblockchainapi import TheBlockchainAPIResource, SolanaNetwork
import requests
import json
class SolEnd:
def __init__(self):
self.addr_to_nick = {}
self.BLOCKCHAIN_API_RESOURCE = TheBlockchainAPIResource(
api_key_id=""
,
api_secret_key=""
)
self.users_profile = {}
def connect(self):
server = "https://solana-mainnet.phantom.tech"
client = Client(server)
return client
def balance(self, address, client):
return 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, address):
address_of_tokens = []
link = f'https://public-api.solscan.io/account/tokens?account={address}'
res = requests.get(link).json()
for tokens in res:
address_of_tokens.append(tokens['tokenAddress'])
print(address_of_tokens)
return address_of_tokens
def get_nft_metadata(self, nft_address):
nft_metadata = self.BLOCKCHAIN_API_RESOURCE.get_nft_metadata(
mint_address=nft_address,
network=SolanaNetwork.MAINNET_BETA
)
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"]
fin = name + '\n' + info + '\n' + "price is not set now, you can offer it"
return fin
def bind(self, binder, holder, nft_address):
self.users_profile[holder] = {"token": nft_address,
"binder": binder}
if __name__ == "__main__":
address = 'H2hFezqB6JNVUixUMttJogFr3KvhTDX4bLvT8Rq4eJwW'
print(SolEnd().req(address))