Basic Example

Initialise the SDK

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 dashboard
const clientPub = "<YOUR-APP-CLIENT-KEY>";
const secretKey = "<YOUR-APP-SECRET-KEY>";

// Create your provider instance here
const provider = new ethers.providers.InfuraProvider(
  "matic",
  "<INFURA_API_KEY>"
);

// Create a wallet using the private key and the provider
const wallet = new ethers.Wallet("<PRIVATE-KEY>", provider);

// Create a OneRamp instance, passing the network name, the provider, and the wallet to its constructor
const oneRamp = new OneRamp(
  "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 number
const tx = await oneRamp.offramp("usdt", 10, "2567XXXXXXX");

Full Example code:

import { OneRamp } from '@oneramp/sdk';
import { ethers } from "ethers";

// Your app keys from the oneRamp dashboard
const clientPub = "<YOUR-APP-CLIENT-KEY>";
const secretKey = "<YOUR-APP-SECRET-KEY>";

// Create your provider instance here
const provider = new ethers.providers.InfuraProvider(
  "matic",
  "<INFURA_API_KEY>"
);

// Create a wallet using the private key and the provider
const wallet = new ethers.Wallet("<PRIVATE-KEY>", provider);

// Create a OneRamp instance, passing the network name, the provider, and the wallet to its constructor
const oneRamp = new OneRamp(
  "matic",
  clientPub,
  secretKey,
  provider,
  wallet
);

async function main() {
  try{
    // Attempt to withdraw 10 amount of usdt to phone
    const tx = await oneRamp.offramp("usdt", 10, "2567XXXXXXX");

    console.log(tx)
    catch(error) {
      console.log(error)
    }
  }
}

Last updated