@phala/index
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

inDEX JavaScript SDK

Getting Started

npm install @phala/index
import {Client} from '@phala/index'
const client = new Client()
await client.isReady

EVM Chain

import {lookupAsset} from '@phala/index'
import {Wallet, ethers} from 'ethers'

const privateKey = '0x…'
const wallet = new Wallet(privateKey)
const recipient = '0x…'
const solution = [
  // JSON solution
]

const moonbeam = client.createEvmChain('Moonbeam')
const asset = lookupAsset('Moonbeam', 'WGLMR')
const amount = ethers.parseEther('1')
const simulateResults = await client.simulateSolution(solution, recipient)
const approvalTx = await moonbeam.getApproval(
  asset.location,
  wallet.address,
  amount
)
if (approvalTx) {
  await wallet.signTransaction(approvalTx)
}
const deposit = await moonbeam.getDeposit(
  asset.location,
  amount,
  recipient,
  solution
)
const tx = await wallet.sendTransaction(deposit.tx)
const task = await client.getTask(deposit.id)

Substrate Chain

import {lookupAsset} from '@phala/index'
import Keyring from '@polkadot/keyring'

const mnemonic = 'mnemonic'
const recipient = '0x…'
const keyring = new Keyring({type: 'sr25519'})
const pair = keyring.addFromUri(mnemonic)
const solution = [
  // JSON solution
]

const simulateResults = await client.simulateSolution(solution, recipient)
const phala = client.createPhalaChain('Phala')
await phala.isReady // necessary for substrate chains
const deposit = await phala.getDeposit(
  lookupAsset('Phala', 'PHA').location,
  1_000_000_000_000n,
  recipient,
  solution
)
const txHash = await deposit.tx.signAndSend(pair)
const task = await client.getTask(deposit.id)

Readme

Keywords

none

Package Sidebar

Install

npm i @phala/index

Weekly Downloads

3

Version

1.1.5

License

MIT

Unpacked Size

604 kB

Total Files

8

Last publish

Collaborators

  • phala