Polkadot Parachain

Sign Transaction

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

getParachainSignedTransaction()

Supported Coin Type

  • Parachain - Astar(ASTR)

  • Parachain Asset- Astar Asset(XC20)

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'/810'/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: Parachain's decimals.

  • RPCUrl: Network RPC endpoints.

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

  • fee decimals: fee's decimals.

Requirements

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

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

Useage

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

const httpProvider = new HttpProvider('https://evm.astar.network');
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, // For tokens, method: api.tx.assets.transfer(contract, to, amount).method,
});

const sigHash = signerPayload.toRaw().data;

const transactionJson = {
  coinType: DcentWebConnector.coinType.PARA,
  sigHash: sigHash,
  path: `m/44'/810'/0'/0/0`,
  decimals, // 18
  fee,
  symbol: 'ASTR',
  RPCUrl: 'https://evm.astar.network',
  feeSymbol: 'ASTR',
  feeDecimals, // 18
};

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

Returned response object

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

Please note that for Astar EVM transactions, you can use the getEthereumSignedTransaction() and getTokenSignedTransaction() methods with the chain ID set to 592.

Last updated