Pin an existing CID on IPFS to your Pinata account
Usage
import { PinataSDK } from "pinata-web3";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const pin = await pinata.upload.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
Returns
type PinByCIDResponse = {
id: string;
ipfsHash: string;
status: "prechecking" | "retrieving";
name: string;
updated?: boolean;
};
Parameters
cid
Target CID already on IPFS
const pin = await pinata.upload.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
Add optional metadata to file
const pin = await pinata.upload
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
.addMetadata({
name: "hello.txt",
keyValues: {
whimsey: 100
}
})
group (Optional)
Upload to a specific group by passing in the groupId
const pin = await pinata.upload
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
.group("b07da1ff-efa4-49af-bdea-9d95d8881103")
key (Optional)
Upload a file using a secondary API key generated through keys.create()
const pin = await pinata.upload
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
.key("GENERATED_API_JWT")
peerAddress (Optional)
Accepts an array of host node IDs to peer with
const pin = await pinata.upload
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng")
.peerAddress([
"/ip4/hostNode1ExternalIP/tcp/4001/ipfs/hostNode1PeerId",
"/ip4/hostNode2ExternalIP/tcp/4001/ipfs/hostNode2PeerId"
])