How to on ramp or off ramp

Move assets between fiat & crypto.

Overview

One of the most important parts of getting started in crypto is onboarding your own funds. FunWallet has on and off ramp integration with Moonpay that enables you to ramp funds directly to your FunWallet without any additional transfer. In this guide, I’ll show you how to enable the ramp. I also will assume some basic knowledge covered in the Quick Start but I’ll quickly walk through all the steps again.

Import required objects

import {
FunWallet,
Auth,
configureEnvironment,
generatePrivateKey,
} from "@funkit/core";

Configuring the FunWallet environment

To begin, we need to set up the environment for your FunWallet. We’ll be using the Goerli testnet and a gasless sponsor. Please visit our dashboard to receive your own production apiKey.

await configureEnvironment({
chain: "goerli",
gasSponsor: {
sponsorAddress: "0xCB5D0b4569A39C217c243a436AC3feEe5dFeb9Ad",
},
apiKey: "ZrhepzWGxm74D0sqstuhT6dGrJxhoy8SZIToX6I3",
});

Creating Auth with a private key

We’ll use a private key as the authentication method and I’ll provide us with one.

const privateKey = generatePrivateKey();
const auth = new Auth({ privateKey });

Creating FunWallet with Auth

With the Auth instance that we created in the step before, we are now able to initialize and create your FunWallet.

const funWallet = new FunWallet({
users: [{ userId: auth.getAddress() }],
uniqueId: auth.getWalletUniqueId(),
});
funWallet.create(auth, userId);

Create the ramp

Now that we’ve created FunWallet, we can create an on ramp that converts fiat currencies to crypto in one line of code.

On ramp

This will return a URL, that takes your users to Moonpay where they can set up their on ramp methods.

const URL = await funWallet.onRamp();

Off ramp

Similarly, we can off ramp in one line of code.

const URL = await funWallet.offRamp();

Summary

Putting together all the pieces we have onRamp() that you can use to on ramp funds to a FunWallet.

,
bridge.js
import { FunWallet, Auth, configureEnvironment, generatePrivateKey } from "@funkit/core"
const onRamp = async () => {
await configureEnvironment({
chain: "goerli",
gasSponsor: {
sponsorAddress: "0x175C5611402815Eba550Dad16abd2ac366a63329"
},
apiKey: "ZrhepzWGxm74D0sqstuhT6dGrJxhoy8SZIToX6I3"
})
const privateKey = generatePrivateKey()
const auth = new Auth({ privateKey })
const funWallet = new FunWallet({
users: [{ userId: await auth.getAddress() }],
uniqueId: await auth.getWalletUniqueId()
})
const URL = await funWallet.onRamp()
console.log(URL)
}
onRamp()