Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Phala-Network/index-sdk
inDEX JavaScript SDK
https://github.com/Phala-Network/index-sdk
Last synced: 15 days ago
JSON representation
inDEX JavaScript SDK
- Host: GitHub
- URL: https://github.com/Phala-Network/index-sdk
- Owner: Phala-Network
- Created: 2023-08-28T07:51:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-18T12:52:02.000Z (10 months ago)
- Last Synced: 2024-07-31T12:07:48.687Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.27 MB
- Stars: 0
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# inDEX JavaScript SDK
## Getting Started
```sh
npm install @phala/index
``````javascript
import {Client} from '@phala/index'
const client = new Client()
await client.isReady
```### EVM Chain
```javascript
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
```javascript
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)
```