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
_1npm i terra.onchainpayments
For Yarn
_1yarn 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_28function 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_28function 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.
_1yarn 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:
_2import 'node-libs-react-native/globals';_2import 'react-native-get-random-values';
Also, add resolvers to your metro.config.js
_8module.exports {_8 // ..._8 resolver: {_8 // ..._8 extraNodeModules: require('node-libs-react-native'),_8 },_8 // ..._8}