Transfers

Get Transfers

The getTransfers function gets all transfers that belongs to your entity and matches the query.

Parameters

Takes an object that represents the query params to filter the transfers, with the properties below. If null, the request will return all transfers under your main entity.

  • transferId (string): The Loop ID of the transfer you are looking for.

  • wallet (string): Filter transfers by the from / to wallet addresses.

  • networkId (number): The network Id of the transfers.

  • entityId (string): The entity Id that the transfers are associated with. This can be your env var entity ID or a child entity ID.

Returns

  • Promise<object[]>: A promise that resolves with the array of transfers.

Example

import { loop } from "@loop-crypto/loop-sdk";

const opts = {
  wallet: "0xBBb634939e33FE1A2458E99104Dc3e8274816324",
  networkId: 5
};

const transfers = await loop.getTransfers(opts);
console.log(transfers);

Sign Transfer

The signTransfer function takes a transfer object as input and returns a signed message with your Loop contract signer key.

Parameters

The transfer object requires the following properties:

  • invoiceId (string): Invoice ID related to the transfer. Can be a stripe ID or an internal ID you have in your system.

  • fromAddress (string): Wallet address where funds are pulled from.

  • toAddress (string): Wallet address where funds are going to.

  • tokenAddress (string): Address of the token used to pay.

  • amount (number): Amount to bill. If transfer.usd is true, specify the amount in cents (e.g. 2999 for $29.99). If transfer.usdis false, specify the native token amount (e.g. 1000000 for 1 USDC).

  • usd (boolean): Whether the amount is denominated in USD.

Returns

  • Promise<string>:A promise that resolves with the signed message of the transfer.

Example

import { loop } from "@loop-crypto/loop-sdk";

const signature = await loop.signTransfer({
    invoiceId: "invoice-1",
    fromAddress: "0xBBb634939e33FE1A2458E99104Dc3e8274816324",
    toAddress: "0xa593dba004b3858F4820801EB98aCEC42666F3d6",
    tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    amount: 1000,
    usd: true,
});
console.log(signature);

Sign and Send a Transfer

The signSendTransfer function signs the transfer and sends it to the Loop API. It takes in a transfer object as its parameter and returns a promise that resolves with the list of transfers that were successfully sent.

Parameters

The transfer object has the following properties:

  • invoiceId (string): Invoice ID related to the transfer. Can be the stripe ID or an internal ID you have in your system.

  • itemId (string): Loop Item ID that is associated with the transfer.

  • fromAddress (string): Wallet address where funds are pulled from.

  • toAddress (string): Wallet address where funds are going to.

  • tokenAddress (string): Address of the token used to pay.

  • amount (number): Amount to bill. If opts.usd is true, specify the amount in cents (e.g. 2999 for $29.99). If opts.usd is false, specify the native token amount (e.g. 1000000 for 1 USDC).

  • usd (boolean): Whether the amount is denominated in USD.

  • billDate (number) [Optional]: The date the transfer should be executed on, formatted as a UNIX timestamp in seconds. Not specified or 0 indicates immediate processing.

  • entityId (string) [Optional]: If not specified, it will use your LOOP ID inferred by the API KEY.

Returns

  • Promise<object[]>: A promise that resolves with the list of transfers that were successfully sent.

Example

import { loop } from "@loop-crypto/loop-sdk";

const transfer = {
    invoiceId: "invoice-1",
    itemId: "c8693c1b-b573-4d12-bd1d-e388f6ebc6e3",
    fromAddress: "0xBBb634939e33FE1A2458E99104Dc3e8274816324",
    toAddress: "0xa593dba004b3858F4820801EB98aCEC42666F3d6",
    tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    amount: 2999,
    usd: true,
    billDate: 1623771600,
    entityId: "92a3d1a6-851f-11ec-b34d-7ab92fc139db"
};
const result = await loop.signSendTransfer(transfer);
console.log(result);

Send Transfers

The sendTransfers function sends a list of transfers to the Loop API.

Parameters

Takes an array of transfers to be sent to Loop, with the properties below:

  • invoiceId (string): The invoice ID of the transfer.

  • entityId (string): Your Loop Entity ID.

  • networkId (number): The network Id of the transfer.

  • planId (string): Loop Item ID that is associated with the transfer.

  • from (string) Wallet address where funds are pulled from.

  • to (string): Wallet address where funds are going to.

  • token (string): Address of the token used to pay.

  • amount (string): Amount to bill. If usd is true, specify the amount in cents (e.g. "2999" for $29.99). If usd is false, specify the native token amount (e.g. "1000000" for 1 USDC).

  • usd (boolean): Whether the amount is denominated in USD.

  • signature (string): The signed transfer message. If delegated signing is enabled, this should just be an empty string.

  • billDate (number): The date the transfer should be executed on, formatted as a UNIX timestamp in seconds. Use the value 0 to indicate immediate processing.

Returns

  • Promise<object[]>: A promise that resolves with a list of successfully sent transfers.

Example

import { loop } from "@loop-crypto/loop-sdk";

const firstBillDate = Math.floor(Date.now() / 1000);
const billingPeriodSeconds = loop.utils.billingPeriodInSeconds(
    1, "week"
);
const transfers = [];
for (let i = 1; i <= 5; i++) {
    const invoiceId = `invoice-${i}`;
    const billingAmount = 1000;
    const signature = await loop.signTransfer({
        invoiceId: invoiceId,
        fromAddress: "0xBBb634939e33FE1A2458E99104Dc3e8274816324",
        toAddress: "0xa593dba004b3858F4820801EB98aCEC42666F3d6",
        tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        amount: billingAmount,
        usd: true,
    });
    transfers.push({
        invoiceId: invoiceId,
        entityId: process.env.LOOP_API_ID,
        amount: billingAmount.toString(),
        from: "0xBBb634939e33FE1A2458E99104Dc3e8274816324",
        to: "0xa593dba004b3858F4820801EB98aCEC42666F3d6",
        token: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        usd: true,
        networkId: parseInt(process.env.LOOP_CONTRACT_NETWORK_ID),
        planId: "c8693c1b-b573-4d12-bd1d-e388f6ebc6e3",
        billDate: firstBillDate + billingPeriodSeconds * i,
        signature: signature,
    });
}
const result = await loop.sendTransfers(transfers);
console.log(result);

Cancel Transfers

The cancelTransfers function cancels a list of transfers on the Loop API.

Parameters

  • transferIds (string[]): The list of transfer IDs to be cancelled.

Returns

  • A promise that resolves with the list of transfers that were cancelled.

Example

import { loop } from "@loop-crypto/loop-sdk";

const result = await loop.cancelTransfers([
    "a17e123d-6467-45e6-8c74-6891c9c7b0f5", 
    "fb4a891d-8e5f-4e4c-8a8a-b3cade359253"
]);
console.log(result);

Last updated