A Typescript software development toolkit for interfacting with the Demex chain.
Package | Description |
---|---|
@demex-sdk/core | Core utilities and environment constants |
@demex-sdk/codecs | GPRC codecs generated from Demex chain |
@demex-sdk/examples | References and examples on how to use libraries listed here |
@demex-sdk/sdk | Main wrapper abstraction for interacting with Demex chain |
@demex-sdk/wallet | Wallet abstraction for an account |
@demex-sdk/transact | Transaction utilities for assembling Demex transactions |
@demex-sdk/amino-types | Provides amino types map for cosmjs libraries to enable signing with amino |
@demex-sdk/bridge | Utilities to interact with external chains useful for executing cross-chain transfers |
@demex-sdk/hydrogen | Fetch client for Hydrogen offchain service |
@demex-sdk/insights | Fetch client for Insights offchain service |
@demex-sdk/node-ledger | Additional tools to enable connecting wallet with a hardware wallet device |
@demex-sdk/polynetwork | Utilities for carrying out deprecated cross-chain transfers via PolyNetwork |
@demex-sdk/websocket | Demex websocket service client |
This section demonstrates the basic usage of @demex-sdk/*
packages. Reference @demex-sdk/examples for more.
- Install the package using
yarn
ornpm
.
Using yarn
:
yarn install @demex-sdk/sdk
Using npm
:
npm i @demex-sdk/sdk
- Query chain data
import { DemexSDK } from "@demex-sdk/sdk";
const sdk = DemexSDK.instance();
const queryClient = await sdk.getQueryClient();
// fetch chain ID
console.log("chain ID", await queryClient.chain.getChainId());
// fetch active markets
console.log("active markets", await queryClient.market.MarketAll({ isActive: true }));
// fetch address balances
console.log("balances", await queryClient.chain.getAllBalances("swth1hexzxh3apqpqzzchhgynks2xr8ar8qvdf3m9cw"));
- Connect wallet
import { DemexSDK } from "@demex-sdk/sdk";
const mnemonic = "<your mnemonics>";
const sdk = DemexSDK.instanceWithMnemonic(mnemonic);
console.log("address", sdk.wallet!.bech32Address);
- Send transaction
import { TxTypes } from "@demex-sdk/core";
import { MsgSend } from "@demex-sdk/codecs/data/cosmos/bank/v1beta1/tx";
// initialize the SDK as demonstrated above
...
// send the desired transaction
const tx = await sdk.sendTxs([{
typeUrl: TxTypes.MsgSend,
value: MsgSend.fromPartial({
amount: [{
amount: "1",
denom: "swth",
}],
fromAddress: sdk.wallet!.bech32Address,
toAddress: "swth1hexzxh3apqpqzzchhgynks2xr8ar8qvdf3m9cw",
})
}]);
console.log("tx result", tx);
console.log("hash", tx.transactionHash);
To build the project, run the following command:
npx turbo run build