@tinyverse.space/web3storage
v0.0.42
Published
Tinyverse web3storage JavaScript API client
Downloads
53
Readme
Getting started
Install the package using npm
npm install @tinyverse.space/web3storage
or yarn:
yarn add @tinyverse.space/web3storage
See [the getting started docs][w3storage-docs-w3name-getting-started] for more information.
You can also find full API reference documentation for the client at https://tinyverse-web3.github.io/web3storage
Usage
The web3stoage
package exposes several "top-level" or module-scoped functions like , , and , along with a few classes like and that are returned from and accepted by the API functions.
In the examples below, the module is imported as Name
using the ES module import syntax:
import * as Web3storage from '@tinyverse-space/web3storage'
const userPk = "0x5448862c64c6bEFc44ED957FAd45F22aeeDaC800";
const ipfsStorage = await Web3Storage.createIpfsStorage(userPk, {
autoSync: true, // default true
syncTryTimeout: 5000, // default 5000ms
syncCallback: msg => console.info(msg)
})
// setSyncCallback set synchronization callback, which will be called back after synchronizing the remote IPFS node
ipfsStorage.setSyncCallback((msg: any) => {
console.info(msg)
})
// put user data to local ipfs node
await ipfsStorage.put('note', { 0: "hello world" })
// get user data from local ipfs node
const data = await ipfsStorage.get('note')
console.info(data)
// resume user data from remote ipfs node
await ipfsStorage.resume()
Configuration
http {
......
server {
listen 443 ssl;
server_name localhost;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
ssl_certificate /Users/dujuan/work/ssl/server.pem;
ssl_certificate_key /Users/dujuan/work/ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location /ipfs/api/v0/name/publish {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Request-Method' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' '*' always;
if ($request_method = 'OPTIONS') {
return 204;
}
proxy_pass http://localhost:5001/api/v0/name/publish;
proxy_set_header Host $host;
}
......
}
......
}