
Amiri m.
asked 03/11/25Blockchains Assignment/Computer Science
Hello, I need help with a blockchains course. I would like to find a tutor who is available on a weekly basis until March. I will post my first task/code so that you get a feel for what kind of questions I will be asked. Thank you in advance.
Using the template provided at ipfs.py, create two functions
- "pin_to_ipfs()" which takes a Python dictionary, and stores the dictionary (as JSON) on IPFS. The function should return the Content Identifier (CID) of the data stored.
- "get_from_ipfs(cid)" which takes as input an IPFS CID and returns a Python dictionary containing the content. For this function, you may assume the content identified by the CID is valid JSON content. For example, you may assume that the CID does not refer to an image, video or other type of binary content that cannot be easily JSONified.
MY CODE:
import requests
import json
def pin_to_ipfs(data):
assert isinstance(data,dict), f"Error pin_to_ipfs expects a dictionary"
#YOUR CODE HERE
json_data = json.dumps(data)
url = "https://ipfs.infura.io:5001/api/v0/add"
headers = {
"Authorization": REMOVED API"
}
response = requests.post(url, headers=headers, files={"file": json_data})
response_data = response.json()
cid = response_data['Hash']
return cid
def get_from_ipfs(cid,content_type="json"):
assert isinstance(cid,str), f"get_from_ipfs accepts a cid in the form of a string"
#YOUR CODE HERE
url = f"https://ipfs.infura.io:5001/api/v0/cat?arg={cid}"
response = requests.get(url)
data = response.json()
assert isinstance(data,dict), f"get_from_ipfs should return a dict"
return data
1 Expert Answer
Srinivas T. answered 03/16/25
Working professional - trying to help new graduates with job sear
If you're looking for a tutor for your blockchain course, I'd be happy to help with your assignments on a weekly basis until March.
This code shows you're working with IPFS, which is commonly used in blockchain applications for storing off-chain data in a decentralized way.
Your course will likely cover more blockchain concepts like consensus mechanisms, smart contracts, and cryptographic primitives as you progress. Please let me know.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Susan D.
Hi, please know Ask an Expert is a platform for academic questions. The following Help Center article may be helpful in answering your question: https://support.wyzant.com/hc/en-us/articles/209611913-How-do-I-find-a-tutor. If you need any assistance at any time, please contact our Customer Support Team at [email protected] and we will follow up as soon as we can.03/12/25