Skip to content

lcnem/pxb-client-ts

Repository files navigation

pxb-client-ts

Install

npm install --save pxb-client

Example

Peg

See tsjs-xpx-chain-sdk for details.

import { Account, NetworkType } from "tsjs-xpx-chain-sdk";
import { proximax } from "pxb-client";

const sender = Account.createFromPrivateKey("", NetworkType.TEST_NET);

// get unsigned tx
const unsignedTx = proximax.peg(...);

// sign
const signedTx = account.sign(unsignedTx, ...);

// broadcast
const http = new TransactionHttp("");
const res = await http.announce(signedTx).toPromise();

Unpeg

import { CosmosSDK, AccAddress, PrivKeySecp256k1 } from "cosmos-client";
import { auth, StdTx } from "cosmos-client/x/auth";
import { proximax_bridge } from "pxb-client";

const sdk = new CosmosSDK(hostURL, chainID);

// get account info
const privKeyBuffer = await sdk.generatePrivKeyFromMnemonic(mnemonic);
const privKey = new PrivKeySecp256k1(privKeyBuffer);
const fromAddress = AccAddress.fromPublicKey(
  privKey.getPubKey().toBuffer()
);
const account = await auth
  .accountsAddressGet(sdk, fromAddress)
  .then((res) => res.data);

// get unsigned tx
const unsignedStdTx = await proximax_bridge
  .unpegPost(sdk, { ... })
  .then((res) => res.data);

// sign
const signedStdTx = auth.signStdTx(
  sdk,
  privKey,
  unsignedStdTx,
  account.account_number,
  account.sequence,
);

// broadcast
const result = await auth.txsPost(sdk, signedStdTx, "sync").then((res) => res.data);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published