-
Notifications
You must be signed in to change notification settings - Fork 1
/
wheels.py
44 lines (33 loc) · 1.05 KB
/
wheels.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
import requests
import json
import os
from dotenv import load_dotenv
from pathlib import Path
from web3.auto import w3
load_dotenv()
headers = {
"Content-Type": "application/json",
"pinata_api_key": os.getenv("PINATA_API_KEY"),
"pinata_secret_api_key": os.getenv("PINATA_SECRET_API_KEY"),
}
def initContract():
with open(Path("Wheels.json")) as json_file:
abi = json.load(json_file)
return w3.eth.contract(address=os.getenv("WHEELS_ADDRESS"), abi=abi)
def convertDataToJSON(time, description):
data = {
"pinataOptions": {"cidVersion": 1},
"pinataContent": {
"name": "Example Alteration Report",
"description": description,
"image": "ipfs://bafybeihsecbomd7gbu6qjnvs7jinlxeufujqzuz3ccazmhvkszsjpzzrsu",
"time": time,
},
}
return json.dumps(data)
def pinJSONtoIPFS(json):
r = requests.post(
"https://api.pinata.cloud/pinning/pinJSONToIPFS", data=json, headers=headers
)
ipfs_hash = r.json()["IpfsHash"]
return f"ipfs://{ipfs_hash}"