Topup
Cryptocurrency purchases through our fiat-to-crypto partners.
initiateTopup
Initiates a top up tx with the specified provider right from the dapp. Please refer below for supported values of params and providers
*Currently only Ramp Network is supported.
info
Topup api doesn't require the user to be logged in with Torus
const paymentStatus = await torus.initiateTopup(provider, params);
Parameters
provider
-enum
(required) : The specified payment partner. Supported options for provider aremoonpay
wyre
coindirect
params
-PaymentParams
(optional) : The topup tx params. used to autofill the form for that specific providerselectedAddress
-string
(optional): The address to top upselectedCurrency
-string
(optional) : The fiat currency supported. e.g.: "USD". In case an unsupported currency is specified, it throwsfiatValue
-Number
(optional) : The fiat value. It must be between the max and min value supported by that providerselectedCryptoCurrency
-string
(optional) : The crypto currency supported. e.g.: "SOLANA_SOL". In case an unsupported crypto currency is specified, it throwscryptoAmount
-Number
(optional) : The crypto currency amount. Converted fiat value must be between the max and min value supported by that provider
Returns
Promise<boolean>
: Returns a promise which resolves to aboolean
indicating whether user has successfully completed the flow
Reference
torus.paymentProviders = {
rampnetwork: {
minOrderValue: 1,
maxOrderValue: 100,
validCryptoCurrencies: ["SOLANA_SOL", "SOLANA_USDC"],
},
};
interface PaymentParams {
selectedAddress?: string;
selectedCurrency?: string;
fiatValue?: Number;
selectedCryptoCurrency?: string;
crytoAmount?: Number;
}
Examples
// Default using wallet selected address
const paymentStatus = await torus.initiateTopup("rampnetwork");
const paymentStatus = await torus.initiateTopup("rampnetwork", {
selectedCurrency: "USD",
selectedCryptoCurrency: "SOLANA_SOL",
selectedAddress: "< Recipient's Solana Public Key(base58) >",
});
const paymentStatus = await torus.initiateTopup("rampnetwork", {
selectedCurrency: "USD",
});
*Note - for Ramp Network selectedCurrency and fiatValue have to be used together. For more details please check Ramp Network documentation(https://docs.ramp.network/configuration#fiatcurrency-and-fiatvalue)