Skip to main content

Upload JSON to IPFS

Upload JSON metadata to IPFS for use in atom creation. Returns the IPFS hash, name, and size.

Mutation Structure​

mutation UploadJsonToIpfs($json: jsonb!) {
uploadJsonToIpfs(json: $json) {
hash
name
size
}
}

Variables​

VariableTypeRequiredDescription
jsonjsonbYesJSON object to upload
{
"json": {
"name": "Ethereum",
"description": "A decentralized blockchain platform",
"image": "ipfs://QmXnnyufdzAWL5CqZ2RnSNgPbvCc1ALT73s6epPrRnZ1Xy",
"url": "https://ethereum.org",
"type": "Thing"
}
}

Response Fields​

FieldTypeDescription
hashString!IPFS content hash (CID)
nameString!Filename on IPFS
sizeString!File size

Expected Response​

{
"data": {
"uploadJsonToIpfs": {
"hash": "QmYx8C3kNN1sFSx5bZPyN1sFSx5b8MqKu2r6CTSJ",
"name": "metadata.json",
"size": "256"
}
}
}

Interactive Example​

Query

mutation UploadJsonToIpfs($json: jsonb!) {
  uploadJsonToIpfs(json: $json) {
    hash
    name
    size
  }
}

Variables

Click "Run Query" to execute the GraphQL query and see results

Common Metadata Schemas​

Thing Schema​

{
"name": "Ethereum",
"description": "A decentralized blockchain platform that enables smart contracts",
"image": "ipfs://Qm...",
"url": "https://ethereum.org"
}

Person Schema​

{
"name": "Vitalik Buterin",
"description": "Co-founder of Ethereum",
"image": "ipfs://Qm...",
"email": "vitalik@ethereum.org",
"identifier": "vitalik.eth",
"url": "https://vitalik.ca"
}

Organization Schema​

{
"name": "Ethereum Foundation",
"description": "Non-profit supporting Ethereum development",
"image": "ipfs://Qm...",
"url": "https://ethereum.foundation",
"email": "info@ethereum.org"
}

Use Cases​

Complete Atom Creation Workflow​

Upload metadata and use the IPFS hash for atom creation:

import { GraphQLClient } from 'graphql-request'
import { API_URL_PROD } from '@0xintuition/graphql'

const client = new GraphQLClient(API_URL_PROD)

async function prepareAtomMetadata(thing: {
name: string
description: string
image: string
url?: string
}) {
const mutation = `
mutation UploadJsonToIpfs($json: jsonb!) {
uploadJsonToIpfs(json: $json) {
hash
name
size
}
}
`

const result = await client.request(mutation, { json: thing })
return result.uploadJsonToIpfs.hash
}