0.1.0 • Published 3 years ago
matrix-world-voucher-flow-js-sdk v0.1.0
API reference
core apis VoucherClient
You can also check Demo-front-page for reference
/** Setup global FCL instance
*
* @async
* @param {FLowEnv} env - FlowEnv.{localEmulator, flowTestnet, flowMainnet}
* @returns {Promise<void>}
*/
public async setupGlobalFcl(env: FLowEnv): Promise<void>;
/**
* Send transferFUSD transaction
*
* @async
* @param {string} to - addresses of recipient
* @param {string} amount - amount in string (1.0 means 1.0 FUSD)
* @returns {Promise<string>} transactionId which can be used to verify the payment to server
*/
public async transferFUSD(to: string, amount: string): Promise<string>;
/**
* Get FUSDBalance of an Account
*
* @async
* @param {string} address - account address
* @returns {Promise<number>} account balance (1.0 means 1.0 FUSD)
*/
public async FUSDBalance(address: string): Promise<number>;
// TODO
public async transferFLOW(to: string, amount: string): Promise<string>;
public async FLOWBalance(): Promise<number>;
Local development guide
Setup Flow CLI
sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"
Sample steps (Local Emulator):
- Setup Flow CLI (Above)
Got to contracts directory, where a flow.json is located
cd ./packages/contracts/
Open a new terminal and start emulator
flow emulator start
Run bootstrap script
make bootstrap-local
Start dev-wallet docker (Account information here is default service account in Local Emulator)
docker run -it \ -e PORT=8701 \ -e FLOW_ACCESS_NODE=http://localhost:8080 \ -e FLOW_ACCOUNT_KEY_ID=0 \ -e FLOW_ACCOUNT_PRIVATE_KEY=2eae2f31cb5b756151fa11d82949c634b8f28796a711d7eb1e52cc301ed11111 \ -e FLOW_ACCOUNT_PUBLIC_KEY=31a053a2003d95760d8fff623aeedcc927022d8e0767972ab507608a5f611636e81857c6c46b048be6f66eddc13f5553627861153f6ce301caf5a056d68efc29 \ -e FLOW_INIT_ACCOUNTS=0 \ -e FLOW_ACCOUNT_ADDRESS=0xf8d6e0586b0a20c7 \ -e FLOW_AVATAR_URL=https://avatars.onflow.org/avatar/ \ --network host \ ghcr.io/onflow/fcl-dev-wallet:latest
Import FCL from SDK
import { fcl, FclVoucherClient, FLowEnv } from "matrix-world-voucher-flow-js-sdk/dist"; const client = new FclVoucherClient(); await client.setupGlobalFcl(FLowEnv.localEmulator); await fcl.logIn(); await fcl.authenticate();
sample code for sending FUSD
import { fcl, FclVoucherClient } from "matrix-world-voucher-flow-js-sdk/dist"; // transferFUSD const client = new FclVoucherClient(); const ret = await client.transferFUSD("0x01cf0e2f2f715450", "10.0"); console.log(ret);
sample code for getting FUSD balance
import { fcl, FclVoucherClient } from "matrix-world-voucher-flow-js-sdk/dist"; // transferFUSD const client = new FclVoucherClient(); const ret = await client.FUSDBalance("0x01cf0e2f2f715450"); console.log(ret);
0.1.0
3 years ago