1.0.1 • Published 12 months ago

pkp-xrpl v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 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

12 months ago

1.0.0

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago