Import the OneRamp class from the package and create a new instance by providing the necessary parameters:
import { OneRamp } from'@oneramp/sdk';import { ethers } from"ethers";// Your app keys from the oneRamp dashboardconstclientPub="<YOUR-APP-CLIENT-KEY>";constsecretKey="<YOUR-APP-SECRET-KEY>";// Create your provider instance hereconstprovider=newethers.providers.InfuraProvider("matic","<INFURA_API_KEY>");// Create a wallet using the private key and the providerconstwallet=newethers.Wallet("<PRIVATE-KEY>", provider);// Create a OneRamp instance, passing the network name, the provider, and the wallet to its constructorconstoneRamp=newOneRamp("matic", clientPub, secretKey, provider, wallet);
Find the clientPub & secret from your dashboard after you create your app. See how
Off Ramp
The offramp method allows you to initiate a withdrawal of funds to a designated phone number. This method is used to provide users with a seamless way to convert their specified token into fiat currency, which can then be conveniently received via their provided phone number.
Here's an example of how to use the offramp method in JavaScript:
// Attempt to withdraw 10 amount of USDT to a specified phone numberconsttx=awaitoneRamp.offramp("usdt",10,"2567XXXXXXX");
Full Example code:
import { OneRamp } from'@oneramp/sdk';import { ethers } from"ethers";// Your app keys from the oneRamp dashboardconstclientPub="<YOUR-APP-CLIENT-KEY>";constsecretKey="<YOUR-APP-SECRET-KEY>";// Create your provider instance hereconstprovider=newethers.providers.InfuraProvider("matic","<INFURA_API_KEY>");// Create a wallet using the private key and the providerconstwallet=newethers.Wallet("<PRIVATE-KEY>", provider);// Create a OneRamp instance, passing the network name, the provider, and the wallet to its constructorconstoneRamp=newOneRamp("matic", clientPub, secretKey, provider, wallet);asyncfunctionmain() {try{// Attempt to withdraw 10 amount of usdt to phoneconsttx=awaitoneRamp.offramp("usdt",10,"2567XXXXXXX");console.log(tx)catch(error) {console.log(error) } }}