Polkadot

Sign Transaction

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

getPolkadotSignedTransaction()

Supported Coin Type

  • POLCKADOT(DOT)

Parameters

  • unsignedTx: unsigned hexadecimal tx Polkadot Docs

  • path: key path, wallet sign with that private key with a given key path (BIP32 ex) "m/44'/354'/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: polkadot's decimals.

Requirements

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

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

Useage

import { ApiPromise, HttpProvider } from '@polkadot/api'

const httpProvider = new HttpProvider('https://rpc.polkadot.io');
const api = await ApiPromise({ provider: httpProvider });
// Wait until we are ready and connected
await api.isReady;

const blockNumber = await api.rpc.chain.getHeader()
const blockHash = await api.rpc.chain.getBlockHash(blockNumber.number.toHex())
// create SignerPayload
const signerPayload = api.createType('SignerPayload', {
  genesisHash: api.genesisHash,
  runtimeVersion: api.runtimeVersion,
  version: api.extrinsicVersion,
  blockHash: blockHash,
  blockNumber: blockNumber.number,
  era: api.createType('ExtrinsicEra', {
    current: blockNumber.number,
    period: 50
  }),
  nonce,
  address: to,
  method: api.tx.balances.transfer(to, amount).method,
});

const sigHash = signerPayload.toRaw().data

const transactionJson = {
  coinType: DcentWebConnector.coinType.POLKADOT,
  sigHash: sigHash,
  path: `m/44'/354'/0'/0/0`,
  decimals, // 12
  fee,
  symbol: 'DOT',
}

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

Returned response object

{
  "header": {
    "version": "1.0",
    "response_from": "polkadot",
    "status": "success"
  },
  "body": {
    "command": "transaction",
    "parameter": {
    "signed_tx": "0x31aa13b5e04cb6fc6381ea0520bf7f6727ebdb6e96cd7ca8625bb3e3dd36cf0e2cee4ece13aa9f7ddc09ee10c74aa00af954201829d8016317f10f5a921dcc0d"
    }
  }
}

Last updated