UNPKG

@akashicpay/sdk

Version:

SDK to interact with the Akashic ecosystem

133 lines (101 loc) 4.25 kB
# AkashicPay - Node SDK A library to interact with the AkashicChain network, written in TypeScript. # Installing Install the package with: ```sh npm install @akashicpay/sdk #or yarn add @akashicpay/sdk ``` # Usage AkashicPay works with both ESM and CommonJS formats: ```typescript import { AkashicPay } from "@akashicpay/sdk"; ``` ```typescript const { AkashicPay } = require("@akashicpay/sdk"); ``` **Features** - Send crypto via **Layer 1** and **Layer 2** (Akashic Chain) - Create wallets for your users into which they can deposit crypto - Fetch balance and transaction details - Completely _Web3_: No login or API-key necessary. Just supply your Akashic private key, which stays on your server. The SDK signs your transactions with your key and sends them to Akashic Chain. - Supports **Ethereum** and **Tron** **Getting Started** 1. Create an account on AkashicLink (Google Chrome Extension or iPhone/Android App) 2. Visit [AkashicPay](https://www.akashicpay.com) and connect with AkashicLink. Set up the URL(s) you wish to receive callbacks for. 3. Integrate the SDK in your code. This example configuration uses many optional build arguments, for illustration purposes: ```typescript import { ACDevNodes, ACNodes, AkashicPay, Environment, } from "@akashicpay/sdk"; // use whatever secret management tool you prefer to load the private key // from your AkashicLink account. It should be of the form: // `"0x2d99270559d7702eadd1c5a483d0a795566dc76c18ad9d426c932de41bfb78b7"` // In development, each developer could have their own, or omit this (and // the l2Address), in which case the SDK will create and use a new pair. // you can instead use your Akashic Link account's 12-word phrase, using the // `build()` argument `recoveryPhrase` const privateKey = process.env.akashicKey; // this is the address of your AkashicLink account. Of the form "AS1234..." const l2Address = process.env.l2Address; // in development, you will use our testnet and testnet L1 chains const environment = process.env.environment == "production" ? Environment.Production : Environment.Development; // optional, the SDK will try to find the fastest node if omitted const targetNode = environment == "development" ? ACDevNodes.Singapore1 : ACNodes.Singapore1; // instantiate an SDK instance, ready to use const akashicPay = await AkashicPay.build({ privateKey, l2Address, environment, targetNode, }); ``` AkashicPay is now fully setup and ready to use. # Testing You can also use AkashicPay with the AkashicChain Testnet & **Sepolia** (Ethereum) and **Shasta** (Tron) testnets, useful for local development and preprod environments. To do this, follow the same procedure as above but make sure you use _testnet_ versions of AkashicLink and [AkashicPay](https://testnet.akashicpay.com) ```typescript import { AkashicPay, Environment } from "@akashicpay/sdk"; const privateKey = process.env.akashicTestKey; const l2Address = process.env.testL2Address; const akashicPay = await AkashicPay.build({ privateKey, l2Address, environment: Environment.Development, }); ``` You can now create an L1-wallet on a testnet: ```typescript const { address } = await akashicPay.getDepositAddress( NetworkSymbol.Tron_Shasta, "EndUser123" ); ``` ## Faucet During testing and local development, you need cryptocurrency on the testnets to do anything meaningful. Akashic provides a simple faucet where you can request some coins and tokens on Shasta and Sepolia by supplying your L2-address/identity: https://faucet.testnet.akashicchain.com/ If you require further funds, the official Tron Discord provides users with either 5000 TRX or USDT on Shasta every day. You can check to see if your balance has increased with: ```typescript const balances = await akashicPay.getBalance(); // -> [{networkSymbol: 'TRX-SHASTA', balance: '5000'}, ...] ``` # Documentation For more in-depth documentation describing the SDKs functions in detail, explanations of terminology, and guides on how to use AkashicPay.com, click [here](https://docs.akashicpay.com/) # License This project is licensed under the [MIT](./LICENSE) License