-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.py
More file actions
37 lines (31 loc) · 765 Bytes
/
sample.py
File metadata and controls
37 lines (31 loc) · 765 Bytes
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
"""
Example of NFT Metadata Upload
"""
from ipyfs import Files
import json
# You can customize the host and port on any controller.
files = Files(
host="http://localhost", # Set IPFS Daemon Host
port=5001 # Set IPFS Daemon Port
)
# Read the file and upload it to IPFS.
with open("sample.png", "rb") as f:
files.write(
path=f"/{f.name}",
file=f,
create=True
)
# Get the information of the uploaded file.
info = files.stat('/ipyfs.png')
# Generate NFT metadata.
metadata = {
"name": "Sample NFT",
"description": "Sample NFT Description",
"image": f"ipfs://{info['result']['Hash']}"
}
# Upload the NFT metadata to IPFS.
files.write(
path="/metadata.json",
file=json.dumps(metadata),
create=True
)