Skip to content

Instantly share code, notes, and snippets.

@pat36
Created November 19, 2017 22:13
Show Gist options
  • Save pat36/60001886e9387eb7117be1efe276e0d8 to your computer and use it in GitHub Desktop.
Save pat36/60001886e9387eb7117be1efe276e0d8 to your computer and use it in GitHub Desktop.
import ipfsapi
import json
ipfs = ipfsapi.connect()
# JSON:
# { "data" : "something...", "previousBlock" : "ipfs hash to previous block"}
# genesisHash is "Qm00000000000000000000000000000000000000000000"
# when previousBlock == genesisHash then we reached the first block
genesisHash = "Qm00000000000000000000000000000000000000000000"
previousHash = "0"
hash = "QmXtdjRXaXQaWmzbDNJmLNURLCGSVMnPcPdXoDKzbqSnBb"
ipfs.cat(hash)
while previousHash != genesisHash:
obj = json.loads(ipfs.cat(hash))
previousHash = hash = obj['previousBlock']
print(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment