Package Exports
- ipfs-pinata-toolkit
- ipfs-pinata-toolkit/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ipfs-pinata-toolkit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
IPFS Pinata Toolkit
๐ Easy IPFS integration with Pinata - Just provide your keys and start pinning!
A simple, user-friendly npm package that makes it easy to store data on IPFS using Pinata. Perfect for developers who want to quickly integrate IPFS storage without dealing with complex configurations.
โจ Features
- ๐ Simple Authentication - Just add your Pinata credentials to
.env - ๐ฆ Easy Data Pinning - Pin any JSON data with a single function call
- ๐ File Upload Support - Pin files directly to IPFS
- ๐ Retrieve Content - Get your pinned content back easily
- ๐ List Management - View all your pinned content
- โ Built-in Testing - Verify your setup works
- ๐ฏ TypeScript Ready - Full TypeScript support (coming soon)
๐ Quick Start
1. Install the Package
npm install ipfs-pinata-toolkit2. Create your .env file
Create a .env file in your project root:
JWT=your_pinata_jwt_token_hereGet your JWT token from Pinata:
- Sign up/Login to Pinata
- Go to API Keys section
- Create a new API key
- Copy the JWT token
3. Start Using It!
const IPFSPinataToolkit = require('ipfs-pinata-toolkit');
async function main() {
// Initialize (automatically reads from .env)
const ipfs = new IPFSPinataToolkit();
// Pin your data to IPFS
const result = await ipfs.pinToIPFS({
name: 'John Doe',
email: 'john@example.com',
image: 'https://example.com/photo.jpg',
bio: 'Software developer',
data: 'Any additional data you want to store'
});
if (result.success) {
console.log('๐ Pinned to IPFS!');
console.log('๐ IPFS Hash:', result.ipfsHash);
console.log('๐ URL:', result.ipfsUrl);
}
}
main();๐ API Reference
new IPFSPinataToolkit()
Creates a new instance and automatically authenticates with Pinata using credentials from your .env file.
pinToIPFS(params)
Pins JSON data to IPFS.
Parameters:
name(string, required) - Name for the contentemail(string, optional) - Email associated with the contentimage(string, optional) - Image URL or base64 datadata(any, optional) - Any additional data to storemetadata(object, optional) - Additional metadata...otherParams- Any other parameters you want to include
Returns: Promise with result object containing ipfsHash, ipfsUrl, etc.
pinFileToIPFS(filePath, options)
Pins a file to IPFS.
Parameters:
filePath(string, required) - Path to the fileoptions(object, optional) - Additional options and metadata
getFromIPFS(ipfsHash)
Retrieves content from IPFS using its hash.
listPins()
Lists all your pinned content.
๐ง Examples
Pin User Profile Data
const result = await ipfs.pinToIPFS({
name: 'Alice Smith',
email: 'alice@example.com',
image: 'https://example.com/alice.jpg',
bio: 'Blockchain enthusiast',
social: {
twitter: '@alice',
github: 'alice-dev'
}
});Pin NFT Metadata
const result = await ipfs.pinToIPFS({
name: 'Cool NFT #001',
image: 'https://example.com/nft.png',
description: 'A unique digital collectible',
attributes: [
{ trait_type: 'Color', value: 'Blue' },
{ trait_type: 'Rarity', value: 'Rare' }
]
});Pin a File
const result = await ipfs.pinFileToIPFS('./my-document.pdf', {
name: 'Important Document',
metadata: { category: 'documents' }
});๐งช Testing
Run the included test to verify everything works:
npm testOr run the example:
npm start๐ Environment Variables
Your .env file should contain:
# Pinata JWT Token (recommended - only this is needed)
JWT=your_pinata_jwt_token
# Alternative format (also supported)
PINATA_JWT=your_pinata_jwt_token๐จ Error Handling
The package includes comprehensive error handling:
const result = await ipfs.pinToIPFS({ name: 'Test' });
if (result.success) {
console.log('Success!', result.ipfsHash);
} else {
console.error('Error:', result.error);
}๐ค Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
๐ License
MIT License - feel free to use in your projects!
๐ Links
Made with โค๏ธ for the decentralized web