1.0.3-alpha.0 • Published 5 months ago

@heliofi/sdk v1.0.3-alpha.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Helio SDK

Introduction

The Helio SDK is a packaged module to make integrating Helio and our components as easy and as quickly as possible into your front end web site or store so you can start accepting Helio web3 payments.

It wraps and enhances the Helio API away into one NPM package which is easy to install and upgrade.

The Helio SDK is written in Typescript.

Please use the latest production version. Only used ALPHA versions if advised to do so.

Solana is currently supported with Polygon and ETH following soon.

Installation

yarn add @heliofi/sdk

After installing the SDK please import this into your project:

import { Helio } from "@heliofi/sdk";

Helio SDK Services

Detailed below are the methods used via the SDK to interact with the Helio API

Please ensure you select the correct 'Cluster' or network during deployment.

Properties table for the HelioSDK

MethodsParamsReturnDescription
constructoroptions?: { cluster: ClusterHelioType; customApiUrl: string }voidset properties, cluster available values: devnet, mainnet, testnet
setClustercluster: ClusterHelioTypevoidset cluster available value
setCustomApiUrlcustomApiUrl: stringvoidset custom api url
currencyServicenoneCurrencyService, neverreturns object CurrencyService
defaultCurrencyServicenoneDefaultCurrencyService, neverreturns object DefaultCurrencyService
apiServicenoneHelioApiConnector, neverreturns object HelioApiAdapter
solExplorerServicenoneSolExplorerService, neverreturns object SolExplorerService
polygonExplorerServicenonePolygonExplorerService, neverreturns object PolygonExplorerService
ethExplorerServicenoneEthereumExplorerService, neverreturns object EthereumExplorerService
tokenConversionServicenoneTokenConversionService, neverreturns object TokenConversionService
paylinkServicenonePaylinkSubmitService, neverreturns object PaylinkSubmitService
polygonPaylinkServicenonePolygonPaylinkSubmitService, neverreturns object PolygonPaylinkSubmitService
ethPaylinkServicenoneEthPaylinkSubmitService, neverreturns object EthPaylinkSubmitService
paystreamStartServicenonePaystreamStartService, neverreturns object PaystreamStartService
paystreamCancelServicenonePaystreamCancelService, neverreturns object PaystreamCancelService
configServicenoneConfigService, neverreturns object ConfigService
solAvailableBalanceServicenoneSolAvailableBalanceService, neverreturns object SolAvailableBalanceService
ethAvailableBalanceServicenoneEthereumAvailableBalanceService, neverreturns object EthereumAvailableBalanceService
polygonAvailableBalanceServicenonePolygonAvailableBalanceService, neverreturns object PolygonAvailableBalanceService
availableBalanceServicenoneAvailableBalanceService, neverreturns object AvailableBalanceService
type ClusterHelioType = 'devnet' | 'testnet' | 'mainnet';

Methods

Properties table for the CurrencyService

MethodsParamsReturnDescription
getCurrenciesnonePromise<Currency[]>if currencies are empty adds currencies
getCurrencyBySymbolsymbol: stringCurrency, undefined, neverget currency by symbol (e.g. "SOl")
getCurrencyByMintmint: stringCurrency, neverget currency by mint address
getCurrencyByMintOptionalmint: stringCurrency, undefinedget currency by mint address
getCurrencyBySymbolAndBlockchain{ symbol: string; blockchain?: BlockchainSymbol; }Currency, undefined, neverget currency by symbol and blockchain
getCurrenciesByTypeAndBlockchain{ type: CurrencyType; blockchain?: BlockchainSymbol; }Currency[]get currency by type and blockchain
import { BlockchainSymbol, Currency, CurrencyType } from '@heliofi/common';

Properties table for the DefaultCurrencyService

MethodsParamsReturnDescription
getNativeCurrencyByBlockchainToSymbolblockchain: stringstring, undefinedget native currency by blockchain
getSolCurrencySymbolnonestringget sol native currency
getMaticCurrencySymbolnonestringget matic native currency
getEthCurrencySymbolnonestringget eth native currency
getDefaultCurrencySymbolnonestringget usdc native currency

Properties table for the SolAvailableBalanceService

MethodsParamsReturnDescription
getAvailableBalancepublicKey: PublicKey, connection: ConnectionPromise<AvailableBalance[]>get available balance list
import { Connection, PublicKey } from '@solana/web3.js';

interface AvailableBalance {
    tokenSymbol: string;
    value: number;
}

Properties table for the EthereumAvailableBalanceService

MethodsParamsReturnDescription
getAvailableBalancepublicKey: EVMPublicKeyPromise<AvailableBalance[]>get available balance list
type EVMPublicKey = `0x${string}`;

interface AvailableBalance {
    tokenSymbol: string;
    value: number;
}

Properties table for the PolygonAvailableBalanceService

MethodsParamsReturnDescription
getAvailableBalancepublicKey: EVMPublicKeyPromise<AvailableBalance[]>get available balance list
type EVMPublicKey = `0x${string}`;

interface AvailableBalance {
    tokenSymbol: string;
    value: number;
}

Properties table for the AvailableBalanceService

MethodsParamsReturnDescription
fetchAvailableBalance{ props: AvailableBalanceServiceProps }Promise<number>get available balance
isBalanceEnough{ isTokenSwapped: boolean; quantity?: number; decimalAmount: number; }booleanget is balance enough
import { Connection, PublicKey } from '@solana/web3.js';
import { BlockchainSymbol, Currency } from '@heliofi/common';

type EVMPublicKey = `0x${string}`;

interface TokenSwapQuote {
    paymentRequestId: string;
    routeTokenString: string;
    from: Currency;
    to: Currency;
    slippageBps: number;
    priceImpactPct: number;
    inAmount: number;
    outAmount: number;
    amount: number;
}

interface AvailableBalanceServiceProps {
    publicKey?: PublicKey;
    connection?: Connection;
    evmPublicKey?: EVMPublicKey;
    decimalAmount: number;
    currency?: string;
    canSwapTokens?: boolean;
    swapCurrency?: string;
    quantity?: number;
    tokenSwapQuote?: TokenSwapQuote;
    blockchain?: BlockchainSymbol;
    areCurrenciesDefined: boolean;
}

Properties table for the EthereumExplorerService

MethodsParamsReturnDescription
getEthereumExplorerUrlByClusternonestringget ethereum url
getEthereumExplorerTransactionURLtransactionID: stringstringget ethereum explorer transaction url
getEthereumExplorerAddressURLaddress: stringstringget ethereum explorer address url

Properties table for the PolygonExplorerService

MethodsParamsReturnDescription
getPolygonExplorerUrlByClusternonestringget polygon url
getPolygonExplorerTransactionURLtransactionID: stringstringget polygon explorer transaction url
getPolygonExplorerAddressURLaddress: stringstringget polygon explorer address url

Properties table for the HelioApiAdapter

MethodsParamsReturnDescription
findAddressquery: string, country_code: stringPromise<FetchifyFindAddress>get addresses list by area code and country code
retrieveAddressaddress_id: string, country_code: stringPromise<FetchifyRetrieveAddress>get address more info by address id and country code
getCurrenciesnonePromise<Currency[]>get currencies list
getPaymentRequestByIdPublicid: string, paymentType: PaymentRequestTypePromise<PaymentRequest>get payment data by req. id and payment type
getTokenSwapMintAddressesmintAddress: stringPromise<string[]>get mint addresses list
getTokenSwapQuotepaymentRequestId: string, paymentRequestType: PaymentRequestType, fromMint: string, quantity?: number, normalizedPrice?: number, toMint?: stringPromise<SwapRouteToken>get route token for swap
getLivePriceamount: number, to: string, from: string, paymentRequestId?: string, paymentRequestType?: stringPromise<TokenQuoting>get converted data
getPreparedTransactionMessageurl: string, body: stringPromise<PrepareTransaction>prepare transaction to send
getPreparedTransactionSwapMessageurl: string, body: stringPromise<PrepareSwapTransaction>prepare transaction to send for swap case
getTransactionStatusstatusToken: string, endpoint:string = '/transaction/status'Promise<OnlyContentAndTransactionPaylink>get transaction status
import {
    FetchifyFindAddress,
    PaymentRequest,
    PaymentRequestType,
    FetchifyRetrieveAddress,
    Currency,
    PrepareTransaction,
    PrepareSwapTransaction,
    TokenQuoting,
    SwapRouteToken,
    PaymentRequestType,
    OnlyContentAndTransactionPaylink,
} from '@heliofi/common';

Properties table for the SolExplorerService

MethodsParamsReturnDescription
getSolanaExplorerTransactionURLtransactionID: stringstringget transaction URL by after pay

Properties table for the TokenConversionService

MethodsParamsReturnDescription
convertFromMinimalUnitssymbol: string, minimalAmount: bigint, blockchain?: BlockchainSymbolnumberconvert from minimal amount
convertToMinimalUnitssymbol?: any actualAmount?: numbernumberconvert to minimal amount
formatPricecurrency: Currency, normalizedAmount: numberstringformat price
convertFromMinimalAndRoundsymbol: string, minimalAmount: bigintstringconvert from minimal amount and round
import { BlockchainSymbol, Currency } from '@heliofi/common';

Properties table for the PaylinkSubmitService

MethodsParamsReturnDescription
handleTransaction{ props: CreatePaymentProps }Promise<void>prepare transaction, connect to wallet, send transaction
import { Program } from "@project-serum/anchor";
import { AnchorWallet } from "@solana/wallet-adapter-react";
import { Connection } from "@solana/web3.js";
import { HelioIdl } from '@heliofi/solana-adapter';
import {
    OnlyContentAndSwapTransactionPaylink,
    OnlyContentAndTransactionPaylink,
    CustomerDetails,
    SplitWallet,
} from '@heliofi/common';

type ApproveTransactionResponse = OnlyContentAndTransactionPaylink | OnlyContentAndSwapTransactionPaylink;

interface PaymentEvent {
    transaction?: string;
}

interface ErrorPaymentEvent extends PaymentEvent {
    errorMessage: string;
}

interface PendingPaymentEvent extends PaymentEvent {
    transaction: string;
}

interface BasePaymentProps<ApproveTransactionResponse> {
    onSuccess: (event: SuccessPaymentEvent<ApproveTransactionResponse>) => void;
    onError: (event: ErrorPaymentEvent) => void;
    onPending?: (event: PendingPaymentEvent) => void;
    symbol: string;
    anchorProvider: Program<HelioIdl>;
    wallet: AnchorWallet;
    connection: Connection;
    rateToken?: string;
}

interface CreatePaymentProps
    extends BasePaymentProps<ApproveTransactionResponse> {
    recipientPK: string;
    amount: bigint;
    paymentRequestId: string;
    customerDetails?: CustomerDetails;
    quantity?: number;
    productDetails?: {
        name?: string;
        value?: string;
    };
    splitRevenue?: boolean;
    splitWallets?: SplitWallet[];
    wallet: AnchorWallet;
    connection: Connection;
    canSwapTokens?: boolean;
    swapRouteToken?: string;
    rateToken?: string;
}

Properties table for the PolygonPaylinkSubmitService, EthPaylinkSubmitService

MethodsParamsReturnDescription
handleTransaction{ props: CreatePaymentProps }Promise<void>prepare transaction, connect to wallet, send transaction
import {
    BlockchainSymbol,
    CustomerDetails,
    ProductDetails,
    SplitWallet,
    OnlyContentAndTransactionPaylink,
} from '@heliofi/common';
import { Web3Provider } from '@ethersproject/providers';

enum LoadingModalStep {
    GET_PERMISSION = 'GET_PERMISSION',
    SIGN_TRANSACTION = 'SIGN_TRANSACTION',
    SUBMIT_TRANSACTION = 'SUBMIT_TRANSACTION',
    DEFAULT = 'DEFAULT',
    CLOSE = 'CLOSE',
}

type ClusterHelioType = 'devnet' | 'testnet' | 'mainnet';

interface PaymentEvent {
    transaction?: string;
}

interface ErrorPaymentEvent extends PaymentEvent {
    errorMessage: string;
}

interface PendingPaymentEvent extends PaymentEvent {
    transaction: string;
}

ApproveTransactionResponse = OnlyContentAndTransactionPaylink;

interface SuccessPaymentEvent<ApproveTransactionResponse> extends PaymentEvent {
    data: ApproveTransactionResponse;
    transaction: string;
    paymentPK?: string;
    swapTransactionSignature?: string;
}

interface BasePaymentProps<ApproveTransactionResponse> {
    onSuccess: (event: SuccessPaymentEvent<ApproveTransactionResponse>) => void;
    onError: (event: ErrorPaymentEvent) => void;
    onPending?: (event: PendingPaymentEvent) => void;
    onInitiated?: (event: PaymentEvent) => void;
    setLoadingModalStep: (step: LoadingModalStep) => void;
    onCancel?: () => void;
    symbol: string;
    blockchain?: BlockchainSymbol;
    anchorProvider: Web3Provider;
    rateToken?: string;
    customerDetails?: CustomerDetails;
    productDetails?: ProductDetails;
    mintAddress: string;
    isNativeMintAddress: boolean;
    cluster: ClusterHelioType;
}

interface CreatePaymentProps
    extends BasePaymentProps<ApproveTransactionResponse> {
    recipientPK: string;
    amount: bigint;
    paymentRequestId: string;
    quantity?: number;
    splitRevenue?: boolean;
    splitWallets?: SplitWallet[];
    discountToken?: string;
    canSwapTokens?: boolean;
    swapRouteToken?: string;
    rateToken?: string;
}

Properties table for the PaystreamStartService

MethodsParamsReturnDescription
handleTransaction{ props: CreatePaymentProps }Promise<void>prepare transaction, connect to wallet, send pay stream transaction
import { Program } from "@project-serum/anchor";
import { AnchorWallet } from "@solana/wallet-adapter-react";
import { Connection } from "@solana/web3.js";
import { HelioIdl } from '@heliofi/solana-adapter';
import {
    CustomerDetails,
    OnlyContentAndTransactionPaylink,
} from '@heliofi/common';

interface PaymentEvent {
    transaction?: string;
}

interface ErrorPaymentEvent extends PaymentEvent {
    errorMessage: string;
}

interface PendingPaymentEvent extends PaymentEvent {
    transaction: string;
}

interface CreatePaystreamResponse extends OnlyContentAndTransactionPaylink {} {
    document: {
        id: string;
        startedAt: bigint;
        endedAt: bigint;
    };
}

interface BasePaymentProps<CreatePaystreamResponse> {
    onSuccess: (event: SuccessPaymentEvent<CreatePaystreamResponse>) => void;
    onError: (event: ErrorPaymentEvent) => void;
    onPending?: (event: PendingPaymentEvent) => void;
    symbol: string;
    anchorProvider: Program<HelioIdl>;
    wallet: AnchorWallet;
    connection: Connection;
    rateToken?: string;
}

interface CreatePaystreamProps
    extends BasePaymentProps<CreatePaystreamResponse> {
    interval: number;
    maxTime: number;
    recipientPK: string;
    amount: bigint;
    paymentRequestId: string;
    customerDetails?: CustomerDetails;
    quantity?: number;
    rateToken?: string;
    productDetails?: {
        name?: string;
        value?: string;
    };
    canSwapTokens?: boolean;
    swapRouteToken?: string;
    swapSignedTx?: string;
}

Properties table for the PaystreamCancelService

MethodsParamsReturnDescription
handleTransaction{ props: CancelStreamProps }Promise<void>prepare transaction, connect to wallet, send pay stream for cancel transaction
import { Program } from "@project-serum/anchor";
import { AnchorWallet } from "@solana/wallet-adapter-react";
import { Cluster, Connection } from "@solana/web3.js";
import { HelioIdl } from '@heliofi/solana-adapter';

interface BasePaymentProps<CancelStreamResponse> {
    onSuccess: (event: SuccessPaymentEvent<CancelStreamResponse>) => void;
    onError: (event: ErrorPaymentEvent) => void;
    onPending?: (event: PendingPaymentEvent) => void;
    symbol: string;
    anchorProvider: Program<HelioIdl>;
    wallet: AnchorWallet;
    connection: Connection;
    rateToken?: string;
}

interface CancelStreamResponse extends OnlyContentAndTransactionPaylink {}

interface CancelStreamProps extends BasePaymentProps<CancelStreamResponse> {
    paymentId: string;
}

Properties table for the ConfigService

MethodsParamsReturnDescription
getAssetUrlnonestringget helio assets url
getImageUrlname: stringstringget helio images url
getClusternoneClusterHelioTypereturn selected cluster
getHelioApiBaseUrlnonestringget Helio api base url for current cluster
getPhantomLinkid: string, paymentType: PaymentRequestTypestringget payment url for phantom app
import { PaymentRequestType } from '@heliofi/common';

type ClusterHelioType = 'devnet' | 'testnet' | 'mainnet';

Example

import { HelioSDK, ClusterHelio } from '@heliofi/sdk';
import { Cluster } from '@solana/web3.js';

const cluster = ClusterHelio.Devnet;

//create object HelioSDK
const helioSDK = new HelioSDK({ cluster });

//get curriences
const currencies = helioSDK.currencyService.getCurrencies();

//get helio asset url
const url = helioSDK.configService.getAssetUrl();

//get mint addresses list
const mintAddresses = await helioSDK.apiService.getTokenSwapMintAddresses('mint address');

//get transaction url
const transactionUrl = helioSDK.solExplorerService.getSolanaExplorerTransactionURL('transaction');

//convert to minimal amount
const amount = helioSDK.tokenConversionService.convertToMinimalUnits('symbol', 100);

//handle transaction paylink for sol blockchain
await helioSDK.paylinkService.handleTransaction({...});

//handle transaction paystream for sol blockchain
await helioSDK.paystreamStartService.handleTransaction({...});

//handle cancel transaction paystream for sol blockchain
await helioSDK.paystreamCancelService.handleTransaction({...});

//handle transaction for evm(polygon, ethereum) blockchain
await helioSDK.polygonPaylinkService.handleTransaction({...});
await helioSDK.ethPaylinkService.handleTransaction({...});
1.0.3-alpha.0

5 months ago

2.0.0-alpha.0

5 months ago

0.5.1-alpha.0

5 months ago

2.0.1-alpha.0

5 months ago

1.0.2

9 months ago

1.0.0

12 months ago

0.3.8-alpha.0

1 year ago

0.4.0-alpha.0

12 months ago

0.3.6-alpha.0

1 year ago

0.5.3-alpha.0

12 months ago

0.3.15-alpha.0

1 year ago

0.3.2-alpha.0

1 year ago

0.3.4-alpha.0

1 year ago

0.1.21-alpha.0

1 year ago

0.1.27-alpha.0

1 year ago

0.3.0

1 year ago

0.3.13-alpha.0

1 year ago

0.1.25-alpha.0

1 year ago

0.1.23-alpha.0

1 year ago

0.5.0

12 months ago

0.3.2

1 year ago

0.5.1

12 months ago

0.3.7-alpha.0

1 year ago

0.3.5-alpha.0

1 year ago

0.3.21-alpha.0

1 year ago

0.1.30-alpha.0

1 year ago

0.5.0-alpha.0

12 months ago

0.3.3-alpha.0

1 year ago

0.5.2-alpha.0

12 months ago

0.1.26-alpha.0

1 year ago

0.3.14-alpha.0

1 year ago

0.3.31-alpha.0

1 year ago

0.3.1-alpha.0

1 year ago

0.3.16-alpha.0

1 year ago

0.1.24-alpha.0

1 year ago

0.1.10

1 year ago

0.1.16-alpha.0

1 year ago

0.1.15-alpha.0

1 year ago

0.1.6-alpha.0

1 year ago

0.1.18-alpha.0

1 year ago

0.1.17-alpha.0

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.5-alpha.0

1 year ago

0.1.4-alpha.0

1 year ago

0.1.2-alpha.0

1 year ago

0.1.1-alpha.0

1 year ago

0.1.0

1 year ago

0.0.8-alpha.0

1 year ago

0.0.6-alpha.0

1 year ago

0.0.5-alpha.0

1 year ago

0.0.4-alpha.0

1 year ago

0.0.3-alpha.0

1 year ago

0.0.2-alpha.0

1 year ago