The PrepaidCard API is used to create and interact with prepaid cards within the layer 2 network in which the Card Protocol runs. The PrepaidCard API can be obtained from getSDK() with a Web3 instance that is configured to operate on a layer 2 network (like Gnosis Chain or Sokol).

Example

import { getSDK } from "@cardstack/cardpay-sdk";
let web3 = new Web3(myProvider); // Layer 2 web3 instance
let prepaidCard = await getSDK('PrepaidCard', web3);

Hierarchy

  • PrepaidCardClass

Constructors

Properties

prepaidCardManager: undefined | Contract
layer2Web3: default
layer2Signer?: Signer

Methods

  • This call will return the price in terms of the specified token of how much it costs to have a face value in the specified units of SPEND (§). This takes into account both the exchange rate of the specified token as well as gas fees that are deducted from the face value when creating a prepaid card. Note though, that the face value of the prepaid card in SPEND will drift based on the exchange rate of the underlying token used to create the prepaid card. (However, this drift should be very slight since we are using stable coins to purchase prepaid cards (emphasis on "stable"). Since the units of SPEND are very small relative to wei (§ 1 === $0.01 USD), the face value input is a number type. This API returns the amount of tokens required to achieve a particular face value as a string in native units of the specified token (e.g. wei).

    Example

    // You must send 'amountInDai' to the prepaidCardManager contract
    // to achieve a prepaid card with §5000 face value
    let amountInDAI = await prepaidCard.priceForFaceValue(daiCpxdAddress, 5000);

    Remarks

    Note that if you are creating multiple cards or splitting cards, use this API to ensure the amount to provision for each prepaid card you want to create in order to achieve teh desired face values for each of the prepaid cards created.

    Parameters

    • tokenAddress: string
    • spendFaceValue: number

    Returns Promise<string>

  • This call will return the gas fee in terms of the specified token for the creation of a prepaid card. All prepaid cards will be seeded with some CARD.CPXD in order to pay our gnosis safe relayer for gas. In order to offset these costs, a small fee will be charged when creating or splitting a prepaid card. The gas fee that is charged is returned as a string value in native units of the specified token (e.g. wei). This is the same fee that is accounted for in the PrepaidCard.priceForFaceValue API.

    Example

    let gasFeeInDai = await prepaidCard.gasFee(daiCpxdAddress);
    

    Parameters

    • tokenAddress: string

    Returns Promise<string>

  • This call will return a promise for the most current face value of a prepaid card.

    Example

    let faceValue = await prepaidCard.faceValue(prepaidCardAddress);
    

    Parameters

    • prepaidCardAddress: string

    Returns Promise<number>

  • This call will return a promise for a boolean indicating if the prepaid card can be split.

    Example

    let canSplit = await prepaidCard.canSplit(prepaidCardAddress);
    

    Parameters

    • prepaidCard: string

    Returns Promise<boolean>

  • This call will return a promise for a boolean indicating if the prepaid card can be transferred.

    Example

    let canTransfer = await prepaidCard.canTransfer(prepaidCardAddress);
    

    Parameters

    • prepaidCard: string

    Returns Promise<boolean>

  • This call will return the prepaid card payment limits in units of SPEND (we return a number types since it is safe to represent SPEND as a number in javascript).

    Returns

    a promise object containing min and max number

    Example

    let { min, max } = await prepaidCard.getPaymentLimits();
    

    Remarks

    since the limits are in units of SPEND, it is totally safe to represent as a number vs a string

    Returns Promise<{
        min: number;
        max: number;
    }>

  • This call will pay a merchant from a prepaid card.

    Returns

    a promise for a web3 transaction receipt.

    Example

    let { min, max } = await prepaidCard.getPaymentLimits();
    

    Remarks

    since the limits are in units of SPEND, it is totally safe to represent as a number vs a string

    Parameters

    • txnHash: string

    Returns Promise<SuccessfulTransactionReceipt>

  • Parameters

    • merchantSafe: string
    • prepaidCardAddress: string
    • spendAmount: number
    • Optional txnOptions: TransactionOptions
    • Optional contractOptions: ContractOptions

    Returns Promise<SuccessfulTransactionReceipt>

  • This call will transfer a prepaid card from an issuer to a customer. Note that currently, once a prepaid card has been transferred to a customer (and EOA that did not create the prepaid card), then it becomes no longer transferrable. Additionally, if a prepaid card was used to fund a prepaid card split, the funding prepaid card also becomes non-transferrable, as it is considered the issuer's own personal prepaid card at that point.

    Returns

    a promise for a web3 transaction receipt.

    Example

    let result = await prepaidCard.transfer(prepaidCardAddress, newOwner);
    

    Parameters

    • txnHash: string

    Returns Promise<SuccessfulTransactionReceipt>

  • Parameters

    • prepaidCardAddress: string
    • newOwner: string
    • Optional txnOptions: TransactionOptions
    • Optional contractOptions: ContractOptions

    Returns Promise<SuccessfulTransactionReceipt>

  • This call will use a prepaid card as the source of funds when creating more prepaid cards, in effect "splitting" the prepaid card being used to fund the transaction. Prepaid cards created from the split command are automatically placed in the PrepaidCardInventory. (Note that the prepaid card that is used to fund the creation of more prepaid cards may not be transferred and is considered the issuer's own personal prepaid card.) The creation mechanisms for prepaid cards created via a PrepaidCard.split are identical to PrepaidCard.create in terms of the total cost and gas charges.

    Example

    let result = await prepaidCard.split(
    prepaidCardAddress,
    [5000, 4000], // split into 2 cards: §5000 SPEND face value and §4000 SPEND face value
    undefined,
    "did:cardstack:56d6fc54-d399-443b-8778-d7e4512d3a49"
    );

    Parameters

    • txnHash: string

    Returns Promise<{
        prepaidCards: PrepaidCardSafe[];
        sku: string;
        txReceipt: SuccessfulTransactionReceipt;
    }>

  • Parameters

    • prepaidCardAddress: string
    • faceValues: number[]
    • marketAddress: undefined | string
    • customizationDID: undefined | string
    • Optional txnOptions: TransactionOptions
    • Optional contractOptions: ContractOptions

    Returns Promise<{
        prepaidCards: PrepaidCardSafe[];
        sku: string;
        txReceipt: SuccessfulTransactionReceipt;
    }>

  • This call will create a new prepaid card from a gnosis safe, specifically a gnosis safe that holds tokens that were bridged to the layer 2 network from teh TokenBridge api. From this call you can create 1 or more prepaid cards from the *.CPXD layer 2 tokens (in the Gnosis Chain network, for example). When a token is bridged to a layer 2 network like Gnosis Chain, it will obtain a *.CPXD suffix, indicating that it can participate in the Card Protocol on Gnosis Chain. The face value for the prepaid card does not include the amount of tokens consumed by the gas to create the card as well as fees to create a prepaid card. (Note that the XD in CPXD originally comes from "XDai" the former name of Gnosis Chain.)

    total cost in *.CPXD = (Face value in § * token exchange rate) + fees + gas
    

    Note that gas is charged in the *.CPXD token which will be deducted from your safe. You can use the PrepaidCard.costForFaceValue method to determine what the final cost for a card with a particular face value in units of § will be in the token of your choosing. You can use this amount to create the desired face value for your prepaid card.

    Parma

    faceValues An array of face values in units of § SPEND as numbers. Note there is a maximum of 15 prepaid cards that can be created in a single transaction and a minimum face value of §100 is enforced for each card.

    Example

    let daicpxd = await getAddress('daiCpxd', web3);
    let result = await prepaidCard.create(
    safeAddress,
    daicpxd,
    [5000], // §5000 SPEND face value
    undefined,
    "did:cardstack:56d6fc54-d399-443b-8778-d7e4512d3a49"
    );

    Parameters

    • txnHash: string

    Returns Promise<{
        prepaidCards: PrepaidCardSafe[];
        txnReceipt: SuccessfulTransactionReceipt;
    }>

  • Parameters

    • safeAddress: string
    • tokenAddress: string
    • faceValues: number[]
    • marketAddress: undefined | string
    • customizationDID: undefined | string
    • Optional txnOptions: TransactionOptions
    • Optional contractOptions: ContractOptions
    • Optional force: boolean

    Returns Promise<{
        prepaidCards: PrepaidCardSafe[];
        txnReceipt: SuccessfulTransactionReceipt;
    }>

  • Parameters

    • prepaidCardAddress: string
    • minimumSpendBalance: number
    • onError: ((issuingToken: string, balanceAmount: string, requiredTokenAmount: string, symbol: string) => Error)
        • (issuingToken: string, balanceAmount: string, requiredTokenAmount: string, symbol: string): Error
        • Parameters

          • issuingToken: string
          • balanceAmount: string
          • requiredTokenAmount: string
          • symbol: string

          Returns Error

    Returns Promise<string>

  • Parameters

    • owner: string
    • tokenAddress: string
    • issuingTokenAmounts: BN[]
    • spendAmounts: number[]
    • customizationDID: string = ''
    • marketAddress: string = ZERO_ADDRESS

    Returns Promise<string>

  • Parameters

    • prepaidCardAddress: string
    • totalSpendAmount: number
    • issuingTokenAmounts: BN[]
    • spendAmounts: number[]
    • rate: string
    • customizationDID: string = ''
    • marketAddress: string = ZERO_ADDRESS

    Returns Promise<SendPayload>

  • Parameters

    • prepaidCardAddress: string
    • totalSpendAmount: number
    • issuingTokenAmounts: BN[]
    • spendAmounts: number[]
    • rate: string
    • payload: SendPayload
    • signatures: Signature[]
    • nonce: BN
    • customizationDID: string = ''
    • marketAddress: string = ZERO_ADDRESS

    Returns Promise<GnosisExecTx>

Generated using TypeDoc