Good to know: Currently, Ramper's Near SDK only supports React. A stand-alone version is under consideration.
Overview
Ramper's Near SDK provides an easy wallet solution for developers to integrate into their DApps. Once integrated, your users will be able to log in with a popular OAuth solution and instantly interact with a Near wallet.
Ramper SDK also provides WalletView component, which provides the DApp with various wallet-related functionalities such as fiat-on-ramp, transaction history and token transfers.
In addition, Ramper's Near SDK provides native support to connect your DApp with Near Wallet (more wallet supports coming soon) as well.
To do anything with the NEAR wallet, it needs to be first funded with at least 0.1 NEAR. This is a policy set by NEAR. Whenever a user logs into your DApp through Ramper SDK, you will need to ensure that their wallet is funded.
We recommend checking their wallet balance. Either transfer 0.1 NEAR, or instruct the user to obtain NEAR. All new NEAR wallets remain inactive until initialized.
Install Ramper SDK
Setup Near JS Library
Near JS Library is useful for constructing transactions and providing a host of useful functions to interact with the Near blockchain. You can install the Near JS Library as follows:
Calling await signIn() will launch the log in dialog and return a signInResult when the user successfully logs in or connects an account.
Get logged in user
import { getUser } from '@ramper/near'
const user = getUser()
Displaying User Tokens
Ramper Connect SDK provides an openWallet method that opens an interface which allows the user to view their tokens, export their private key, see their transaction history, and do much more with their Ramper wallet.
import { openWallet } from '@ramper/near'
<button onClick={openWallet}>My Wallet</button>
Once the user logs in, we recommend you replace the login button with a new button that shows their wallet address and triggers the openWallet() function when clicked.
Send token
The following code demonstrates how to send a token from a wallet belonging to the signed in user or a connected wallet.
Users can log out or disconnect their wallet with:
import { signOut } from '@ramper/near'
await signOut()
Yup, it really is just that easy!
If there's any feature you would like to see or design patterns you would like for the Ramper team to adopt, come chat with us (see Introduction for ways to reach us).
Boilerplate Examples
Install Dependencies:
npm i --save @ramper/near bn.js
npm i --save-dev @types/bn.js
Add near-api-js to the <HEAD> tag in your index.html. Alternatively, you can install near-api-js from npm.