D'CENT developer guide
Official siteUser GuideBlogTwitter
  • Introduction
  • How to Connect Your DApp to D’CENT Mobile App
  • In-app browser (dapp browser)
    • Getting Started
    • EVM compatible networks
    • Klaytn network
    • Tron network
  • Dynamic Link
    • Dynamic Link to In-app Browser
    • EIP-681 : Transaction/Payment Request
  • D'CENT WalletConnect (DWC)
    • Introduction
    • Packages
    • D'CENT WalletConnect
    • Test Environment
    • WalletConnect monorepo
  • Collectibles
    • NFT list on Collectibles tab
  • D'CENT biometric wallet for PC
    • D'CENT SDK for PC Environment
    • dcent-web-connector
      • Configurations
      • Device & Accounts Info.
      • Address & XPUB
      • Ethereum & EVM compatible
      • Klaytn
      • Bitcoin
      • XRPL (XRP Ledger)
      • Hedera (HBAR & HTS)
      • Tron (TRX & TRC20)
      • Stellar
      • Tezos (XTZ & XTZ_FA)
      • Vechain
      • Near (NEAR & Near Token)
      • Havah
      • Polkadot
      • Polkadot Parachain
      • Cosmos & Cosmos compatible network
      • Algorand
    • dcent-cli-connector
      • Configurations
      • Device & Accounts Info.
      • Address & XPUB
      • Ethereum & EVM compatible
      • Hedera (HBAR & HTS)
    • dcent-provider
  • D'CENT BIOMETRIC WALLET FOR Mobile
    • D'CENT SDK for Mobile Environment
    • dcent-biometric-sdk-android
      • Setup
      • Initialize
      • Device & Accrouts Info
      • Address & XPUB
      • Bitcoin
      • Ethereum & EVM compatible
      • Klaytn
      • XRPL
      • Binance
      • Stellar
      • Tron
      • Cardano
      • Hedera
      • Stacks
      • Solana
      • Conflux
      • Polkadot
      • Cosmos
      • Tezos
      • Vechain
      • Near
      • Havah
      • Algorand
    • dcent-biometric-sdk-ios
      • Setup
      • Initialize
      • Device & Accrouts Info
      • Address & XPUB
      • Bitcoin
      • Ethereum & EVM compatible
      • Klaytn
      • XRPL
      • Binance
      • Stellar
      • Tron
      • Cardano
      • Hedera
      • Stacks
      • Solana
      • Conflux
      • Polkadot
      • Cosmos
      • Tezos
      • Vechain
      • Near
      • Havah
      • Algorand
  • D'CENT Integrated Packages
    • Web3Modal
    • web3-onboard
  • Misc.
    • Logo & Brand Guideline
Powered by GitBook
On this page
  • Sign Transaction
  • getCosmosSignedTransaction()

Was this helpful?

  1. D'CENT biometric wallet for PC
  2. dcent-web-connector

Cosmos & Cosmos compatible network

PreviousPolkadot ParachainNextAlgorand

Last updated 1 year ago

Was this helpful?

Sign Transaction

The D'CENT Web SDK provides functions for signing transaction of coins.

getCosmosSignedTransaction()

Supported Coin Type

  • COSMOS(ATOM)

  • COREUM(CORE)

Parameters

  • unsignedTx: unsigned hexadecimal tx

  • path: key path, wallet sign with that private key with a given key path (BIP32 ex) "m/44'/118'/0'/0/0").

  • fee: fee, It is fee that wallet displays on the screen.

  • symbol: symbol, It is a symbol that the wallet displays on the screen.

  • decimals: cosmos or coreum's decimals.

Requirements

  • D'CENT Bridge version 1.5.0 or higher is required.

  • D'CENT Biometric Wallet version 2.21.0 or higher is required.

    • COREUM: 2.25.0 or higher is required.

Useage

import message from "@cosmostation/cosmosjs/src/messages/proto";

// signDoc = (1)txBody + (2)authInfo
// ---------------------------------- (1)txBody ----------------------------------
const pubKeyAny = new message.google.protobuf.Any({
      type_url: '/cosmos.crypto.secp256k1.PubKey',
      value: Buffer.from('0a21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex') //temp value
})
const msgSend = new message.cosmos.bank.v1beta1.MsgSend({
  from_address: recAddress,
  to_address: toAddress,
  amount: [{ denom: "uatom", amount: String(100000) }]        // 6 decimal places (1000000 uatom = 1 ATOM)
});

const msgSendAny = new message.google.protobuf.Any({
  type_url: "/cosmos.bank.v1beta1.MsgSend",
  value: message.cosmos.bank.v1beta1.MsgSend.encode(msgSend).finish()
});

const txBody = new message.cosmos.tx.v1beta1.TxBody({ messages: [msgSendAny], memo: "" });

// --------------------------------- (2)authInfo ---------------------------------
const signerInfo = new message.cosmos.tx.v1beta1.SignerInfo({
  public_key: pubKeyAny,
  mode_info: { single: { mode: message.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT } },
  sequence // nonce
});

const feeValue = new message.cosmos.tx.v1beta1.Fee({
  amount: [{ denom: "uatom", amount: String(5000) }],
  gas_limit: 200000
});

const authInfo = new message.cosmos.tx.v1beta1.AuthInfo({ signer_infos: [signerInfo], fee: feeValue });
const bodyBytes = message.cosmos.tx.v1beta1.TxBody.encode(txBody).finish()
const authInfoBytes = message.cosmos.tx.v1beta1.AuthInfo.encode(authInfo).finish()
const signDoc = new message.cosmos.tx.v1beta1.SignDoc({
  body_bytes: bodyBytes,
  auth_info_bytes: authInfoBytes,
  chain_id,
  account_number,
})
let signMessage = message.cosmos.tx.v1beta1.SignDoc.encode(signDoc).finish()

const sigHash = Buffer.from(signMessage).toString('hex')

const transactionJson = {
  coinType: DcentWebConnector.coinType.COSMOS, // or COREUM
  sigHash: sigHash,
  path: `m/44'/118'/0'/0/0`, // (COREUM -> m/44'/990'/0'/0/0)
  decimals, // 6
  fee,
  symbol: 'ATOM', // (COREUM -> CORE)
}

var result
try {
  result = await DcentWebConnector.getCosmomsSignedTransaction(transactionJson);
} catch (e) {
  console.log(e)
  result = e
}

Returned response object

{
  "header": {
    "version": "1.0",
    "response_from": "cosmos",
    "status": "success"
  },
  "body": {
    "command": "transaction",
    "parameter": {
    "signed_tx": "0x31aa13b5e04cb6fc6381ea0520bf7f6727ebdb6e96cd7ca8625bb3e3dd36cf0e2cee4ece13aa9f7ddc09ee10c74aa00af954201829d8016317f10f5a921dcc0d",
    "pubkey": "0x0202903dcb31139bf92e096c3ec85fb9a94ab7dbf02d6234ded604d15ee9650480"
    }
  }
}
Cosmos Docs