Skip to main content

For Node.js & React Devs

Internally manages gas estimation required by the burn tax for successful transactions on the blockchain. Makes it easier for devs to get started with payments on the LUNC/LUNA Blockchains.

Features

  • Written in Typescript, with type definitions
  • Works with React Native, Typescript Ecosystems, in the browser, and Mobile solutions for anyone building on the Terra Ecosystem
  • Makes it easier to manage payments with very simple abstractions

Installation & Configuration

Next, grab the latest version of the payment library off of Npm

For npm


_1
npm i terra.onchainpayments

For Yarn


_1
yarn add terra.onchainpayments

Usage

This package can be used for Mobile & Web Developers, or SDK Developers looking to extend the Terra Platform

Please note: PaymentsManager must be registered as a Singleton to prevent issues with the Connection Pool.

Manage Payments

First, get some testnet tokens for terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v, or use LocalTerra.


_28
// Customer wallets are the ones that make the payment, and pay for the Burn Tax
_28
function ChargeCustomerWithLUNC() {
_28
let businessWallet = 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp';
_28
let customerKeys =
_28
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius';
_28
_28
var manager = new PaymentsManager({ env = Environments.ClassicTestNet })
_28
.configureBusinessWallet(businessWallet)
_28
.configureCustomerKeys(customerKeys);
_28
_28
// Charge the customer a payment of 200,000 LUNC
_28
var tx = await manager.ChargeCustomer(200000);
_28
console.debug(`TX: ${tx.TxFinderHashUrl}`); // Track the Tx Url on Terra.Finder
_28
}
_28
_28
function ChargeCustomerWithLUNA2() {
_28
let businessWallet = 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp';
_28
let customerKeys =
_28
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius';
_28
_28
var manager = new PaymentsManager({ env = Environments.Luna2TestNet })
_28
.configureBusinessWallet(businessWallet)
_28
.configureCustomerKeys(customerKeys);
_28
_28
// Charge the customer a payment of 200 LUNA
_28
var tx = await manager.ChargeCustomer(200);
_28
console.debug(`TX: ${tx.TxFinderHashUrl}`); // Track the Tx Url on Terra.Finder
_28
}

terra.onchainpayments in the browser

Include the following in your browser:


_4
<script
_4
crossorigin
_4
src="https://unpkg.com/@terra-money/terra.onchainpayments/dist/bundle.js"
_4
></script>

You can find a small JSFiddle example that refreshes current Oracle votes here.

terra.onchainpayments in React Native

In order to use terra.onchainpayments inside React Native, you need to add the node-libs-react-native package and react-native-get-random-values package to your React Native app's package.json.


_1
yarn add node-libs-react-native react-native-get-random-values

You will need to register Node.js native modules in an entry point of your application, such as index.tsx:


_2
import 'node-libs-react-native/globals';
_2
import 'react-native-get-random-values';

Also, add resolvers to your metro.config.js


_8
module.exports {
_8
// ...
_8
resolver: {
_8
// ...
_8
extraNodeModules: require('node-libs-react-native'),
_8
},
_8
// ...
_8
}