1.1.0 • Published 1 year ago

flint-gasless-sdk v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Logo

Flint Gasless SDK

Flint gasless SDK (Gaspay) does the magic of enabling gasless feature in any dApp with just a few lines of code. Users can pay in ERC20 tokens to send transactions to the blockchain that needs native tokens otherwise.

Installation

Recommended Node version 16 or higher

  npm install flint-gasless-sdk

Documentation

import { GaspayManager } from "flint-gasless-sdk";

const gaspayManager = new GaspayManager("<FLINT_GASPAY_API_KEY>");

const { dataToSign, functionSignature } =
      await gaspayManager.generateApprovalSignature(
        <WALLET_ADDRESS>,
        <ERC20_TOKEN_ADDRESS>,
        <CHAIN_ID>
);

Get the signature from the user

You can use default ethereum injected by the wallet provider or wagmi to initiate a signature from the user in your dApp.

Note: This will open metamask or any other ethereum wallet

const signature = await ethereum.request({
            method: 'eth_signTypedData_v4',
            params: [walletAddress, JSON.stringify(dataToSign)],
    });

Or

You can read about signing typed data here: wagmi

import { useSignTypedData } from 'wagmi'

const signTypedData = useSignTypedData({
    domain,
    types,
    value,
    onSuccess(data) {
      console.log('Success', data)
      // Call gasless sdk on this data signature returned
    },
  })

Finally send this transaction through the SDK

const txDetails = await gaspayManager.sendApprovalTransaction(
        data,
        functionSig,
        <ERC20_TOKEN_ADDRESS>,
        <WALLET_ADDRESS>,
        <CHAIN_ID>
    );

Get signature for SWAP

const swapSig = await gaspayManager.generateSwapSignature(
    merchantApiKey,
    params,
    chainId,
    walletAddress
)

Send the SWAP signature

const result = await gaspayManager.sendSwapTransaction(
    merchantApiKey,
    signature,
    params,
    chainId,
    walletAddress
)

And voilà!! You have gasless feature enabled in your dApp with just a few lines of code 🥳

API Reference

Generate approval signature

generateApprovalSignature(walletAddress: string, fromToken: string, chainId: string): Promise<ApprovalSignature>;
ParameterTypeDescription
walletAddressstringRequired. User wallet address connected to the dApp
fromTokenstringRequired. ERC20 token in for approval
chainIdstringRequired. Current chain id of the connected account

Send approval transaction

  sendApprovalTransaction(signature: string, functionSignature: string, fromToken: string, walletAddress: string, chainId: string): Promise<any>;
ParameterTypeDescription
signaturestringRequired. Signature returned by the users ethereum wallet
functionSignaturestringRequired. function signature returned by flint gaspay manager
fromTokenstringRequired. ERC20 token address for approval
walletAddressstringRequired. Wallet address of the connected user
chainIdstringRequired. Current chain id of the connected account

Get swap signature

  generateSwapSignature (merchantApiKey: string, params: any, chainId: string, walletAddress: string): Promise<string>
ParameterTypeDescription
merchantApiKeystringRequired. Merchant api key provided by flint
paramsanyRequired. Parameters required for swap in case of the specific merchant
chainIdstringRequired. connected chainId of user's wallet
walletAddressstringRequired. Wallet address of the connected user

Send swap transaction

  sendSwapTransaction (merchantApiKey: string, signature: string, params: any, chainId: string, walletAddress: string): Promise<any>
ParameterTypeDescription
merchantApiKeystringRequired. Merchant api key provided by flint
signaturestringRequired. user signed signature for swap
paramsanyRequired. Parameters required for swap in case of the specific merchant
chainIdstringRequired. connected chainId of user's wallet
walletAddressstringRequired. Wallet address of the connected user

Authors

License

MIT

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago