SuperAPI AI Directory

greenfield

Data & analytics

View repository

Updated 10-30 07:58

About this skill

Greenfield Storage Skill

Purpose

This skill enables Claude to help users interact with BNB Greenfield, a decentralized storage network built by BNB Chain.

What is Greenfield?

BNB Greenfield is a decentralized storage infrastructure that allows users to:

  • Store files in a decentralized manner
  • Control access permissions via blockchain
  • Pay for storage using BNB tokens
  • Integrate with smart contracts on BNB Chain

Key Concepts

  • Bucket - Container for storing objects (like a folder)
  • Object - A file stored in a bucket
  • Storage Provider (SP) - Nodes that store and serve data
  • Payment Account - Account used to pay for storage

MCP Tools

Storage Operations

Tool Description
gnfd_create_bucket Create a new storage bucket
gnfd_delete_bucket Delete an existing bucket
gnfd_list_buckets List all buckets owned by account
gnfd_get_bucket_info Get bucket details
gnfd_get_bucket_full_info Get bucket info with quota usage
gnfd_create_file Upload a file to a bucket
gnfd_create_folder Create a folder in a bucket
gnfd_list_objects List all objects in a bucket
gnfd_get_object_info Get object details
gnfd_download_object Download an object from a bucket
gnfd_delete_object Delete an object from a bucket

Account Operations

Tool Description
gnfd_get_account_balance Get account BNB balance
gnfd_get_all_sps List all storage providers

Payment Operations

Tool Description
gnfd_get_payment_accounts Get payment accounts for address
gnfd_create_payment_account Create a new payment account
gnfd_deposit_to_payment Deposit BNB to payment account
gnfd_withdraw_from_payment Withdraw BNB from payment account
gnfd_get_payment_account_info Get payment account details

Quick Start

Install Greenfield SDK

npm install @bnb-chain/greenfield-js-sdk

Create a Bucket

import { Client } from '@bnb-chain/greenfield-js-sdk'

const client = Client.create(GREENFIELD_RPC_URL, CHAIN_ID)

// Create bucket
const createBucketTx = await client.bucket.createBucket({
  bucketName: 'my-bucket',
  creator: address,
  visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
  chargedReadQuota: '0',
  primarySpAddress: spAddress
})

// Sign and broadcast
const txHash = await createBucketTx.broadcast({
  privateKey: '0x...'
})

Upload a File

import { Client } from '@bnb-chain/greenfield-js-sdk'
import fs from 'fs'

const client = Client.create(GREENFIELD_RPC_URL, CHAIN_ID)

// Read file
const fileBuffer = fs.readFileSync('./myfile.txt')

// Create object (upload)
const createObjectTx = await client.object.createObject({
  bucketName: 'my-bucket',
  objectName: 'myfile.txt',
  creator: address,
  visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
  contentType: 'text/plain',
  redundancyType: 'REDUNDANCY_EC_TYPE',
  payloadSize: fileBuffer.length
})

// Sign transaction
const txHash = await createObjectTx.broadcast({
  privateKey: '0x...'
})

// Upload content to storage provider
await client.object.uploadObject({
  bucketName: 'my-bucket',
  objectName: 'myfile.txt',
  body: fileBuffer,
  txnHash: txHash
})

Download a File

const objectData = await client.object.getObject({
  bucketName: 'my-bucket',
  objectName: 'myfile.txt'
})

// Save to file
fs.writeFileSync('./downloaded.txt', objectData)

List Objects in Bucket

const objects = await client.object.listObjects({
  bucketName: 'my-bucket'
})

for (const obj of objects.objectInfos) {
  console.log(`Name: ${obj.objectName}`)
  console.log(`Size: ${obj.payloadSize} bytes`)
  console.log(`Created: ${obj.createAt}`)
}

Payment System

How Payments Work

  1. Create Payment Account - Dedicated account for storage payments
  2. Deposit BNB - Fund the payment account
  3. Auto-deduction - Storage fees deducted automatically
  4. Monitor Balance - Keep sufficient balance to avoid service interruption

Payment Account Operations

// Create payment account
const createPaymentTx = await client.payment.createPaymentAccount({
  creator: address
})

// Deposit to payment account
const depositTx = await client.payment.deposit({
  creator: address,
  to: paymentAccountAddress,
  amount: '1000000000000000000' // 1 BNB in wei
})

// Withdraw from payment account
const withdrawTx = await client.payment.withdraw({
  creator: address,
  from: paymentAccountAddress,
  amount: '500000000000000000' // 0.5 BNB
})

Storage Providers

Storage Providers (SPs) are nodes that store your data:

// Get list of all storage providers
const sps = await client.sp.getStorageProviders()

for (const sp of sps) {
  console.log(`SP: ${sp.operatorAddress}`)
  console.log(`Endpoint: ${sp.endpoint}`)
  console.log(`Status: ${sp.status}`)
}

Choosing a Storage Provider

  • Location - Choose SP closer to your users
  • Reputation - Check SP history and uptime
  • Price - Compare storage costs
  • Performance - Test download speeds

Access Control

Visibility Types

  • VISIBILITY_TYPE_PUBLIC_READ - Anyone can read
  • VISIBILITY_TYPE_PRIVATE - Only owner can access
  • VISIBILITY_TYPE_INHERIT - Inherit from bucket

Setting Permissions

// Make object public
await client.object.updateObjectInfo({
  bucketName: 'my-bucket',
  objectName: 'myfile.txt',
  visibility: 'VISIBILITY_TYPE_PUBLIC_READ'
})

Common Use Cases

1. Website Hosting

// Upload website files
await uploadFile('my-website', 'index.html', './dist/index.html')
await uploadFile('my-website', 'styles.css', './dist/styles.css')
await uploadFile('my-website', 'app.js', './dist/app.js')

2. NFT Metadata Storage

// Store NFT metadata
const metadata = {
  name: 'My NFT',
  description: 'A unique NFT',
  image: 'gnfd://my-bucket/nft-image.png'
}

await uploadFile('nft-metadata', 'token-1.json', JSON.stringify(metadata))

3. Data Backup

// Backup important data
await uploadFile('backups', `backup-${Date.now()}.zip`, backupData)

Networks

Network Chain ID RPC URL
Greenfield Mainnet 1017 https://greenfield-chain.bnbchain.org
Greenfield Testnet 5600 https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org

Best Practices

  1. Use payment accounts - Don't pay from main wallet
  2. Monitor quota - Track storage usage
  3. Set appropriate visibility - Protect sensitive data
  4. Backup important files - Use multiple SPs for redundancy
  5. Check SP status - Ensure SP is active before operations

Pricing

Storage costs depend on:

  • Storage size - Per GB stored
  • Read quota - Bandwidth for downloads
  • Operation fees - Gas for blockchain transactions

References