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
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
Name | Type | Description |
host | string | The IPFS Node url to connect with. |
port | number | The port number to use. |
ssl | boolean | If true, the |
Return Value
None
Example
caver.ipfs.add
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
Name | Type | Description |
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
Type | Description |
string | The CID(Content Identifier) of the uploaded file. |
Example
caver.ipfs.get
Returns a file addressed by a valid IPFS path.
Parameters
Name | Type | Description |
hash | string | An CID(Content Identifier) of the file to download. |
Return Value
Promise
returns Buffer
Type | Description |
Buffer | The content of the file. |
Example
caver.ipfs.toHex
Converts a CID(Content Identifier) to a Multihash.
Parameters
Name | Type | Description |
hash | string | A CID(Content Identifier) to convert. |
Return Value
Type | Description |
string | The Multihash string. |
Example
caver.ipfs.fromHex
Converts to CID(Content Identifier) from a Multihash.
Parameters
Name | Type | Description |
hash | string | A Multihash to convert. |
Return Value
Type | Description |
string |
Example
Last updated