1.0.1 • Published 10 months ago

pkp-xrpl v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

pkp-xrpl

This module is a modified version of Wallet from xrpl.js.

Getting Started

Installation

npm install pkp-xrpl xrpl
yarn add pkp-xrpl xrpl
pnpm add pkp-xrpl xrpl

Examples

import { PKPXrplWallet } from 'pkp-xrpl';
import {
  TransactionMetadata,
  Client,
  xrpToDrops,
  dropsToXrp,
  getBalanceChanges,
} from 'xrpl';

const pkpWallet = new PKPXrplWallet({
  controllerSessionSigs: sessionSigs,
  pkpPubKey: currentAccount.publicKey,
  litNodeClient,
});
await pkpWallet.init();
console.log(pkpWallet.classicAddress);

const client = new Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
console.log(client.isConnected());

const { classicAddressToFund, balance } = await requestFunding(
  {},
  client,
  0,
  pkpWallet.classicAddress,
  {
    destination: pkpWallet.classicAddress,
    userAgent: 'xrpl.js',
  }
);
console.log(classicAddressToFund, balance);

// Prepare transaction -------------------------------------------------------
const prepared = await client.autofill({
  TransactionType: 'Payment',
  Account: pkpWallet.classicAddress,
  Amount: xrpToDrops('2'),
  Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
});
const max_ledger = (prepared as any).LastLedgerSequence;
console.log('Prepared transaction instructions:', prepared);
console.log('Transaction cost:', dropsToXrp((prepared as any).Fee), 'XRP');
console.log('Transaction expires after ledger:', max_ledger);
// Sign prepared instructions ------------------------------------------------
const signed = await pkpWallet.sign(prepared);
console.log('Identifying hash:', signed.hash);
console.log('Signed blob:', signed.tx_blob);

// Submit signed blob --------------------------------------------------------
const tx = await client.submitAndWait(signed.tx_blob);
// Check transaction results -------------------------------------------------
console.log(
  'Transaction result:',
  (tx.result.meta as TransactionMetadata).TransactionResult
);
console.log(
  'Balance changes:',
  JSON.stringify(
    getBalanceChanges(tx.result.meta as TransactionMetadata),
    null,
    2
  )
);
await client.disconnect();
1.0.1

10 months ago

1.0.0

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago