npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@white-matrix/matrix-world-voucher-flow-js-sdk

v0.7.0

Published

`yarn add @white-matrix/matrix-world-voucher-flow-js-sdk`

Downloads

212

Readme

Install

yarn add @white-matrix/matrix-world-voucher-flow-js-sdk

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

Official Documents

sh -ci "$(curl -fsSL https://storage.googleapis.com/flow-cli/install.sh)"

Sample steps (Local Emulator):

  1. Setup Flow CLI (Above)

  2. Got to contracts directory, where a flow.json is located

    cd ./packages/contracts/

  3. Open a new terminal and start emulator

    flow emulator start

  4. Run bootstrap script

    make bootstrap-local

  5. 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
  6. 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);
    // or
    await client.setupGlobalFcl(FLowEnv.flowTestnet);
    // or
    await client.setupGlobalFcl(FLowEnv.flowMainnet);
    
    await fcl.logIn();
    await fcl.authenticate();

    sample code for checking voucher collection

    const user = await fcl.currentUser().snapshot();
    ret = await client.checkVoucherCollection(user.addr); // true of false
    console.log(ret);

    if false ask use to init collection first

    const user = await fcl.currentUser().snapshot();
    ret = await client.initVoucherCollection();
    console.log(ret);

    make sure use has enough reserved FLOW for storage to hold minted Vouchers

    const user = await fcl.currentUser().snapshot();
    /**
     * Pre-check user storage capabilities
     *
     * @async
     * @param {string} address - userAddress
     * @param {number} currentBalance - userCurrentFlowBalance
     * @param {number} paymentAmount - amount Of Flow user to pay
     * @param {number} numberOfVouchers - number of vouchers user to mint
     * @returns {Promise<void>}
     */
    public async checkCapacity(
        address: string,
        currentBalance: number,
        paymentAmount: number,
        numberOfVouchers: number
    ): Promise<void>;
    
    // e.g.
    const ret = await client.FLOWBalance(user.addr);
    console.log(ret);
    console.log("check capacity");
    try {
        await client.checkCapacity(user.addr, ret, 1000, 50);
    } catch (error) {
        console.log(error);
        // no error
    }
    
    try {
        await client.checkCapacity(user.addr, ret, ret-0.0009, 50);
    } catch (error) {
        console.log(error);
        // Please may sure you have > 0.001 FLOW balance after payment
    }
    
    try {
        await client.checkCapacity(user.addr, ret, ret-0.002, 50000);
    } catch (error) {
        console.log(error);
        // Please reserve more FLOW in your wallet, it seems like will run out of storage and likely cause a failed mint
    }

    sample code for sending FLOW

    const ret = await client.transferFLOW('0x01cf0e2f2f715450', '10.0');
    console.log(ret);

    sample code for sending FLOW

    const ret = await client.transferFLOW('0x01cf0e2f2f715450', '10.0');
    console.log(ret);

    sample code for getting FLOW balance

    const ret = await client.FLOWBalance('0x01cf0e2f2f715450');
    console.log(ret);

    sample code for sending FUSD

    const ret = await client.transferFUSD('0x01cf0e2f2f715450', '10.0');
    console.log(ret);

    sample code for getting FUSD balance

    const ret = await client.FUSDBalance('0x01cf0e2f2f715450');
    console.log(ret);

    sample code for getting all assets

    export interface Asset {
      name: string;
      description: string;
      image: string;
      animation_url: string;
      attributes: string;
      tokenId: string;
      collection: string;
      external_url: string;
    }
    const ret: Asset[] = await client.getAssets('0xf20df769e658c257'); // mainnet admin account for quick testing
    console.log(ret);

    sample code for transferring assets

    const ret = await client.transferVoucher('0x01cf0e2f2f715450', 0);
    console.log(ret);