To activate a funder on NEARamp, we will need
- Developer ID - Account ID of developer's NEAR wallet (e.g.
superdeveloper.testnet
). - RSA Public Key - RSA public key used for verifying JWTs signed by developer - How to
Mainnet: https://sdk.nearamp.dev/nearamp.js
Testnet: https://sdk.testnet.nearamp.dev/nearamp.js
- Import the SDK
<script>
(function (w,d,s,o,f,js,fjs) {
w['NEARamp']=o;w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };
js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script', 'NR', 'https://sdk.testnet.nearamp.dev/nearamp.js'));
</script>
- Load the wallet creation page
/* element into which the page will be loaded */
// <div id="widget-box"> </div>
/* sdk call */
window.NR('init', {
developerID: '<developer.testnet|developer.near>', // Required: Onboarded developer id
grantToken: token, // Required: Token signed by developer private key
targetElement: 'widget-box' , // Required: ID of Parent DOM element for sdk instance
onSuccess: callbackFn, // Optional: When account is created successfully, callbackFn(accountId)
loginConfig: { // Optional: Pass login config authenticate the newly created NEAR account into the app
contractId: '<>'
},
darkMode: true|false // Optional: Use dark mode sdk
});
When a developer ID is onboarded, a funder account is created in the NEARamp contract which holds the developer's deposit and the disbursal amount.
On the developer's app, the end user will use the account creation page loaded by the SDK to create a new funded wallet. To do this, the SDK will generate a passphrase and corresponding keypair for the new account and send the public key to the our server which invokes the account creation method on the contract. The SDK will also generate a different keypair and store it in browser local storage of the app so near-sdk-js
can recognize the account without the user having to leave the page. The user can also use the passphrase to login to the near browser wallet separately.
The developer controls access to account creation using a grant_token
for each SDK instance. The grant_token
functions like a JWT
used for authentication - the developer server signs a token using their private key which NEARamp will verify using the developer's public key to check whether the account creation request is valid.
Using Node.JS:
const jwt = require('jsonwebtoken');
const privateKey = process.env.NEARAMP_SECRET_KEY; // RSA Private Key
function generateJWT() {
const exp = Math.floor(Date.now() / 1000) + (60 * 60); // token expiry window
const token = jwt.sign({ exp }, privateKey, { algorithm: 'RS256'});
return token;
}
Developer funds are deposited and managed by the NEARamp smart contract. Funds can be added/withdrawn by directly calling contract methods via NEAR CLI.
export CONTRACT_NAME="v1.nearamp.near"
# Or Testnet:
export CONTRACT_NAME="v1-alpha.nearamp.testnet"
near view $CONTRACT_NAME get_funder --args '{"account_id":"<developerid>"}' --accountId <developerid>
near call $CONTRACT_NAME self_deposit --accountId <developerid> --deposit "1"
# amount to withdraw in near in yocto. Given example is 1N
near call $CONTRACT_NAME self_withdraw --args '{"amount":"1000000000000000000000000"}' --accountId <developerid>
# transfer_amount in yocto near. Given example is 0.2N
near call $CONTRACT_NAME set_transfer_amount --args '{"transfer_amount":"200000000000000000000000"}' --accountId <developerid>
Please email us on [email protected], and we'd be happy to help with any integration queries