From 4e421fda7be198050e3bf06b805490d6d7eb4f9b Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 18 Nov 2023 09:18:00 +0530 Subject: [PATCH] added: more usage examples, version bump --- README.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47bbb9f..53605e0 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,16 @@ The Superfluid Web3.js Plugin extends the capabilities of the Web3.js library to ## Installation -> Note: Make sure you are using `web3` version 4.0.0 or higher in your project. +> Note: Make sure you are using `web3` version 4.0.2 or higher in your project. ```bash -npm install web3-plugin-superfluid +npm install web3-plugin-superfluid web3@latest --save ``` ## Usage +### Basic Usage + ```js import { Web3 } from "web3"; import { SuperfluidPlugin } from "web3-plugin-superfluid"; @@ -35,6 +37,96 @@ const flowRate = await cfav1Forwarder.methods console.log("FlowRate: ", flowRate.toString()); ``` +### Connecting Accounts to Web3 + +#### With Private Key + +```js +import { Web3 } from "web3"; +import { SuperfluidPlugin } from "web3-plugin-superfluid"; + +const web3 = new Web3("https://rpc-mumbai.maticvigil.com/"); // Any RPC node you wanted to connect with + +// Adding account to web3 with private key +const wallet = web3.eth.accounts.wallet.add("0x..."); // private key +const account = wallet.get(0); + +web3.registerPlugin(new SuperfluidPlugin()); + +const cfav1ForwarderAddress = "0x..."; // varies based on network +const hostAddress = "0x..."; // varies based on network +const cfav1Forwarder = web3.superfluid.cfav1Forwarder(cfav1ForwarderAddress); +const host = web3.superfluid.host(hostAddress); +``` + +#### With Metamask + +```js +import { Web3 } from "web3"; +import { SuperfluidPlugin } from "web3-plugin-superfluid"; + +const web3 = new Web3(window.ethereum); + +const [account] = await window.ethereum.request({ + method: "eth_requestAccounts" +}); + +web3.registerPlugin(new SuperfluidPlugin()); + +const cfav1ForwarderAddress = "0x..."; // varies based on network +const hostAddress = "0x..."; // varies based on network +const cfav1Forwarder = web3.superfluid.cfav1Forwarder(cfav1ForwarderAddress); +const host = web3.superfluid.host(hostAddress); +``` + +### Creating flow: + +```js +const tx = await cfav1Forwarder.methods + .createFlow(token, sender, receiver, 1000, "0x") + .send({ from: account }); +``` + +### Updating flow: + +```js +const tx = await cfav1Forwarder.methods + .updateFlow(token, sender, receiver, 1800, "0x") + .send({ from: account }); +``` + +### Deleting flow: + +```js +const tx = await cfav1Forwarder.methods + .deleteFlow(token, sender, receiver, "0x") + .send({ from: account }); +``` + +### Retrieving flow: + +```js +const flow = await cfav1Forwarder.methods + .getFlowInfo(token, sender, receiver) + .call(); +``` + +### Creating flow with Host: + +```js +const tx = await host.methods + .callAgreement( + cfav1Address, // keep in mind that address is cfa address not cfav1Forwarder address + cfav1Forwarder.methods + .createFlow(token, sender, receiver, 1000, "0x") + .encodeABI(), + "0x" + ) + .send({ from: account }); +``` + +Refer [Superfluid docs](https://docs.superfluid.finance/superfluid/developers/constant-flow-agreement-cfa) for more on respective contract methods. + ### Publishing To publish a new version of the package to npm, run the following command: @@ -47,6 +139,11 @@ npm publish ### Change Log +#### 0.0.9 + +- Added examples for creating, updating, deleting, and retrieving flows using CFAv1Forwarder and Host contracts +- Added examples for connecting accounts to web3 using private key and metamask + #### 0.0.8 - cfav1Forwarder, host contract type exports, function natspec comments diff --git a/package.json b/package.json index 43b92b7..a5bd16d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "web3-plugin-superfluid", - "version": "0.0.8", + "version": "0.0.9", "description": "Superfluid Web3.js Plugin", "author": "Salman Dabbakuti", "license": "MIT",