caver.ipfs
caver.ipfs is a package that provides functionality related to IPFS (InterPlanetary File System).
NOTE caver.ipfs is supported since caver-js v1.5.4.
caver.ipfs.setIPFSNode
caver.ipfs.setIPFSNode(host, port, ssl)Initializes a connection with an IPFS Node. When an IPFS Node information is set through this function, you can upload files to IPFS or load files from IPFS.
Parameters
host
string
The IPFS Node url to connect with.
port
number
The port number to use.
ssl
boolean
If true, the https protocol is used. Otherwise, the http protocol is used.
Return Value
None
Example
> caver.ipfs.setIPFSNode('localhost', 5001, false)caver.ipfs.add
caver.ipfs.add(data)Adds a file to IPFS. The CID(Content Identifier) of the uploaded file is returned.
If the path of a file is passed, the contents of the file are loaded from the path and uploaded to IPFS. If a buffer is passed, it is uploaded to IPFS directly.
Parameters
data
string | Buffer | ArrayBuffer
The path string of a file or a buffer to add to IPFS.
NOTE Buffer is supported since caver-js v1.5.5.
Return Value
Promise returns string
string
The CID(Content Identifier) of the uploaded file.
Example
caver.ipfs.get
Returns a file addressed by a valid IPFS path.
Parameters
Return Value
Promise returns Buffer
Buffer
The content of the file.
Example
caver.ipfs.toHex
Converts a CID(Content Identifier) to a Multihash.
Parameters
Return Value
string
The Multihash string.
Example
caver.ipfs.fromHex
Converts to CID(Content Identifier) from a Multihash.
Parameters
Return Value
string
Example
Last updated