From 60862d71a944ba5605160302070c75b76d96144e Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Tue, 29 Oct 2024 11:45:47 +0700 Subject: [PATCH 1/3] update code examples --- documentation/src/02-installing.md | 14 ++++++-------- documentation/src/03-guides-example.md | 14 ++++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/documentation/src/02-installing.md b/documentation/src/02-installing.md index 3bf4efd..7efc418 100644 --- a/documentation/src/02-installing.md +++ b/documentation/src/02-installing.md @@ -10,21 +10,19 @@ In this section, we will show how to add Filecoin.js library to your web applica ## NodeJS -**Step 1:** Install Filecoin.js using [yarn](https://classic.yarnpkg.com/en/package/jest) +**Step 1:** Install Filecoin.js + ```shell +$ npm install filecoin.js // or $ yarn add filecoin.js ``` -or [npm](https://www.npmjs.com/) -```shell -$ npm install filecoin.js -``` - **Step 2:** Import module using node.js require or ES6 synthax + ```javascript -const { } = require("filecoin.js"); +const filecoin = require("filecoin.js"); // or -import { } from "filecoin.js"; +import * as filecoin from "filecoin.js"; ``` ## Browser diff --git a/documentation/src/03-guides-example.md b/documentation/src/03-guides-example.md index c667c7d..a8d43b1 100644 --- a/documentation/src/03-guides-example.md +++ b/documentation/src/03-guides-example.md @@ -11,15 +11,17 @@ Node JavaScript/TypeScript: ```javascript import { HttpJsonRpcConnector, LotusClient } from 'filecoin.js'; -(async () => { - - const httpConnector = new HttpJsonRpcConnector({ url: __LOTUS_HTTP_RPC_ENDPOINT__, token: __LOTUS_AUTH_TOKEN__ }); - +async function helloFilecoinJs() { + const httpConnector = new HttpJsonRpcConnector({ + url: __LOTUS_HTTP_RPC_ENDPOINT__, + token: __LOTUS_AUTH_TOKEN__ + }); const lotusClient = new LotusClient(httpConnector); const version = await lotusClient.common.version(); - console.log(version); + console.log(`Hello, Filecoin.js v${version}`); +} -})().then().catch(); +await helloFilecoinJs(); ``` Browser: From 7dbe6b4d966d1b959a23c36a18705444f55d7ed6 Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Tue, 29 Oct 2024 19:51:27 +0700 Subject: [PATCH 2/3] update async call, fix typo, and switch to glif node endpoint --- documentation/src/02-installing.md | 3 +- documentation/src/03-guides-example.md | 33 ++++++++++++------- .../src/08-setup-mnemonic-provider.md | 9 +++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/documentation/src/02-installing.md b/documentation/src/02-installing.md index 7efc418..4e728ff 100644 --- a/documentation/src/02-installing.md +++ b/documentation/src/02-installing.md @@ -17,6 +17,7 @@ $ npm install filecoin.js // or $ yarn add filecoin.js ``` + **Step 2:** Import module using node.js require or ES6 synthax ```javascript @@ -27,7 +28,7 @@ import * as filecoin from "filecoin.js"; ## Browser -For using Filecoin.js library in broswer, include the core library in your HTML file and you're ready to go! +For using Filecoin.js library in browser, include the core library in your HTML file and you're ready to go! ```html diff --git a/documentation/src/03-guides-example.md b/documentation/src/03-guides-example.md index a8d43b1..bb5f7ef 100644 --- a/documentation/src/03-guides-example.md +++ b/documentation/src/03-guides-example.md @@ -6,22 +6,23 @@ hide_title: true # Guides example +Before getting into coding, you are going to have to start a [Lotus](https://lotus.filecoin.io/lotus/install/prerequisites/) node. To get started quickly, you can use a [hosted node by Glif](https://api.node.glif.io/). In this example, we can use a RPC endpoint for calibration net: + +``` +https://api.calibration.node.glif.io/rpc/v0 +``` + Node JavaScript/TypeScript: ```javascript import { HttpJsonRpcConnector, LotusClient } from 'filecoin.js'; -async function helloFilecoinJs() { - const httpConnector = new HttpJsonRpcConnector({ - url: __LOTUS_HTTP_RPC_ENDPOINT__, - token: __LOTUS_AUTH_TOKEN__ - }); +(async() => { + const httpConnector = new HttpJsonRpcConnector('https://api.calibration.node.glif.io/rpc/v0'); const lotusClient = new LotusClient(httpConnector); const version = await lotusClient.common.version(); console.log(`Hello, Filecoin.js v${version}`); -} - -await helloFilecoinJs(); +})(); ``` Browser: @@ -30,13 +31,21 @@ Browser: ``` + +If you run your own node, you will have to provide an argument of type `JsonRpcConnectionOptions` to `HttpJsonRpcConnector` constructor. + +```js +const httpConnector = new HttpJsonRpcConnector({ + url: __LOTUS_HTTP_RPC_ENDPOINT__, + token: __LOTUS_AUTH_TOKEN__, +}); +``` + diff --git a/documentation/src/08-setup-mnemonic-provider.md b/documentation/src/08-setup-mnemonic-provider.md index 261e61c..a054195 100644 --- a/documentation/src/08-setup-mnemonic-provider.md +++ b/documentation/src/08-setup-mnemonic-provider.md @@ -5,10 +5,15 @@ hide_title: true --- # Setup mnemonic provider + Node JavaScript/TypeScript: ```javascript -import { HttpJsonRpcConnector, MnemonicWalletProvider } from 'filecoin.js'; +import { + HttpJsonRpcConnector, + LotusClient, + MnemonicWalletProvider, +} from 'filecoin.js'; (async () => { @@ -27,7 +32,7 @@ import { HttpJsonRpcConnector, MnemonicWalletProvider } from 'filecoin.js'; console.log(myAddress); // f1zx43cf6qb6rd... -})().then().catch(); +})(); ``` Browser: From 44924897cff933dbdd1babd1829f7d3f1b3bcb9e Mon Sep 17 00:00:00 2001 From: Pan Chasinga Date: Thu, 31 Oct 2024 11:25:22 +0700 Subject: [PATCH 3/3] keep grinding baby --- documentation/src/01-introduction.md | 4 +-- documentation/src/02-installing.md | 12 ++++----- documentation/src/03-guides-example.md | 36 ++++++++++++++++---------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/documentation/src/01-introduction.md b/documentation/src/01-introduction.md index dc8b898..949e692 100644 --- a/documentation/src/01-introduction.md +++ b/documentation/src/01-introduction.md @@ -4,9 +4,9 @@ title: Introduction hide_title: true --- -# Introduction +## Introduction -## What is Filecoin.js +### What is Filecoin.js The filecoin.js library aims to be a complete library for interacting with local or remote Filecoin nodes. diff --git a/documentation/src/02-installing.md b/documentation/src/02-installing.md index 4e728ff..cd4e15a 100644 --- a/documentation/src/02-installing.md +++ b/documentation/src/02-installing.md @@ -4,13 +4,13 @@ title: Adding Filecoin.js hide_title: true --- -# Adding Filecoin.js +## Adding Filecoin.js In this section, we will show how to add Filecoin.js library to your web application. -## NodeJS +### Node.js -**Step 1:** Install Filecoin.js +#### Step 1: Install Filecoin.js ```shell $ npm install filecoin.js @@ -18,7 +18,7 @@ $ npm install filecoin.js $ yarn add filecoin.js ``` -**Step 2:** Import module using node.js require or ES6 synthax +#### Step 2: Import module using node.js require or ES6 syntax ```javascript const filecoin = require("filecoin.js"); @@ -26,10 +26,10 @@ const filecoin = require("filecoin.js"); import * as filecoin from "filecoin.js"; ``` -## Browser +### Browser For using Filecoin.js library in browser, include the core library in your HTML file and you're ready to go! ```html - + + ``` -If you run your own node, you will have to provide an argument of type `JsonRpcConnectionOptions` to `HttpJsonRpcConnector` constructor. +If you run your own node, you will have to provide an argument of type [`JsonRpcConnectionOptions`](https://filecoin-shipyard.github.io/filecoin.js/docs/api/filecoin.js.httpjsonrpcconnector._constructor_) to [`HttpJsonRpcConnector`](https://filecoin-shipyard.github.io/filecoin.js/docs/api/filecoin.js.httpjsonrpcconnector) constructor. ```js const httpConnector = new HttpJsonRpcConnector({ @@ -48,4 +59,3 @@ const httpConnector = new HttpJsonRpcConnector({ token: __LOTUS_AUTH_TOKEN__, }); ``` -