@cardstack/cardpay-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.54 • Public • Published

cardpay-sdk

This is a package that provides an SDK to use the Cardpay protocol. The SDK is divided into two main parts currently Cardpay and Champer. See here for full documentation

Champer

Champer is the newer part of the SDK that interact with our safe modules.

Cardpay

Cardpay is the older part of the SDK that interact with our protocol smart contracts and token bridge.

  • Assets: Utility to query native and ERC20 token balances

  • Safes: Utility to query safes in our protocol

  • LayerOneOracle: Utility to get the current exchange rates in USD and ETH on layer 1

  • LayerTwoOracle: Utility get the current exchange rates in USD and ETH on layer 2

  • TokenBridgeForeignSide: Interact with the foreign-side bridge ie the bridge contract receiving the tokens on layer 1

  • TokenBridgeHomeSide: Interact with the home-side bridge ie the bridge contract minting the tokens on layer 2

  • PrepaidCard: Create and interact with prepaid cards that are used to pay merchants

  • RevenuePool: Register merchants and claim revenue

  • PrepaidCardMarket: Provision prepaid cards to people who buy them

  • PrepaidCardMarketV2: Similar as PrepaidCardMarket but using updated v2 pattern where prepaid cards are provisioned before being created

  • RewardManager: Register and manage reward program

  • RewardPool: Submit rewards with merkle roots and claim rewards as a user

Installation

yarn add @cardstack/cardpay-sdk

Usage

yarn add @cardstack/cardpay-sdk@1.0.47 ethers@5.7.2 node-fetch@2.6.1
import fetch from "node-fetch";
import { getSDK, JsonRpcProvider } from "@cardstack/cardpay-sdk";
import { Wallet } from "ethers";

//@ts-ignore polyfilling fetch
global.fetch = fetch;

(async () => {
  const mnemonic =
    "<Your mnemonic>";
  const signer = Wallet.fromMnemonic(mnemonic);
  const rpcUrl = "https://eth-goerli.public.blastapi.io";
  const networkId = 5; // 5 for goerli
  const ethersProvider = new JsonRpcProvider(rpcUrl, networkId);
  const scheduledPaymentModule = await getSDK(
    "ScheduledPaymentModule",
    ethersProvider,
    signer
  );
  const { safeAddress } =
    await scheduledPaymentModule.createSafeWithModuleAndGuard(
      undefined,
      undefined,
      { from: signer.address }
    );
  console.log(`Your new safe ${safeAddress} has been created`);
})();

Special Considerations

One item to note that all token amounts that are provided to the API must strings and be in native units of the token (usually wei) unless otherwise noted. All token amounts returned by the API will also be in native units (again, this usually means wei). You can use Web3.utils.toWei() and Web3.utils.fromWei() to convert to and from units of wei. Because ethereum numbers can be so large, it is unsafe to represent these natively in Javascript, and in fact it is very common for a smart contract to return numbers that are simply too large to be represented natively in Javascript. For this reason, within Javascript the only safe way to natively handle numbers coming from Ethereum is as a string. If you need to perform math on a number coming from Ethereum use the BigNumber feature of the ethers library.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.544latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.544
1.0.530
1.0.520
1.0.510
1.0.500
1.0.490
1.0.480
1.0.470
1.0.460
1.0.450
1.0.440
1.0.430
1.0.420
1.0.410
1.0.400
1.0.390
1.0.380
1.0.370
1.0.360
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.260
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00
0.28.370
0.28.360
0.28.350
0.28.340
0.28.330
0.28.320
0.28.310
0.28.290
0.28.280
0.28.270
0.28.260
0.28.210
0.28.200
0.28.190
0.28.180
0.28.170
0.28.160
0.28.150
0.28.140
0.28.130
0.28.120
0.28.110
0.28.100
0.28.90
0.28.70
0.28.20
0.28.10
0.28.00
0.27.440
0.27.430
0.27.420
0.27.410
0.27.400
0.27.380
0.27.370
0.27.360
0.27.350
0.27.340
0.27.330
0.27.320
0.27.310
0.27.300
0.27.290
0.27.280
0.27.260
0.27.250
0.27.240
0.27.230
0.27.220
0.27.200
0.27.190
0.27.180
0.27.170
0.27.160
0.27.150
0.27.140
0.27.130
0.27.110
0.27.100
0.27.90
0.27.80
0.27.60
0.27.50
0.27.40
0.27.30
0.27.20
0.27.10
0.27.00
0.26.100
0.26.90
0.26.80
0.26.50
0.26.40
0.26.30
0.26.20
0.26.10
0.26.00
0.25.20
0.25.10
0.25.00
0.24.50
0.24.40
0.24.30
0.24.20
0.24.10
0.23.00
0.22.10
0.22.00
0.21.50
0.21.30
0.21.20
0.21.10
0.21.00
0.19.500
0.19.490
0.19.480
0.19.470
0.19.460
0.19.450
0.19.440
0.19.430
0.19.420
0.19.410
0.19.400
0.19.390
0.19.380
0.19.370
0.19.360
0.19.340
0.19.330
0.19.320
0.19.300
0.19.290
0.19.260
0.19.250
0.19.240
0.19.230
0.19.220
0.19.210
0.19.190
0.19.180
0.19.160
0.19.150
0.19.140
0.19.130
0.19.120
0.19.110
0.19.100
0.19.90
0.19.80
0.19.70
0.19.60
0.19.50
0.19.40
0.19.30
0.19.20
0.19.10

Package Sidebar

Install

npm i @cardstack/cardpay-sdk

Weekly Downloads

3

Version

1.0.54

License

MIT

Unpacked Size

20.5 MB

Total Files

8

Last publish

Collaborators

  • tintinthong
  • backspace
  • pcjun97
  • jurgen
  • burcunoyan
  • ef4
  • habdelra
  • lukemelia