From b43dfde9904c1fb3e1a167ff99a48a34af5c151a Mon Sep 17 00:00:00 2001 From: hieus207 Date: Thu, 8 Dec 2022 20:44:50 +0700 Subject: [PATCH] Adding code example --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 548938f..27617bf 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,50 @@ const client = await SigningClient.getSigningClient({ }); ``` +### Example +```javascript +import { SigningClient } from '@sei-js/core'; +import { DirectSecp256k1HdWallet } from '@sei-js/proto/node_modules/@cosmjs/proto-signing'; +import { + calculateFee, + GasPrice, + coin + } from "@sei-js/proto/node_modules/@cosmjs/stargate"; + +(async () => { + // Setup wallet + const wallet = await DirectSecp256k1HdWallet.fromMnemonic("your mnemonic", { + prefix: "sei", + }) + + const [{ address: signerAddress }] = await wallet.getAccounts(); + + // Network config + const rpcEndpoint = "https://sei-chain-incentivized.com/sei-chain-tm/"; + + // Setup client + const client = await SigningClient.getSigningClient(rpcEndpoint, wallet); + + // Setup fee + const gasPrice = GasPrice.fromString("0.025usei"); + const executeFee = calculateFee(200_000, gasPrice); + + // Send some token + const result = await client.sendTokens(signerAddress, signerAddress, [coin("1000","usei")], executeFee) + console.log(result) + + // Sign and broadcast custom message + const msg = { + typeUrl: "/seiprotocol.seichain.....", //need custom your typeUrl on seiprotocol and body + value: { + // your body msg + } + } + + const otherResult = await client.signAndBroadcast(signerAddress, [msg], executeFee) + console.log(otherResult) +})() +``` ## Related packages [@sei-js/react](https://www.npmjs.com/package/@sei-js/react) - A react helper library for common @sei-js/core functions