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
  • getNearSignedTransaction()

Was this helpful?

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

Near (NEAR & Near Token)

PreviousVechainNextHavah

Last updated 1 year ago

Was this helpful?

Sign Transaction

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

getNearSignedTransaction()

Supported Coin Type

  • Near(NEAR)

  • Near Token

Parameters

  • unsignedTx: unsigned hexadecimal tx

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

  • optionParams: hexadecimal value of the token method type is used only in near token.

    • '02' : Function call(ft_transfer)

    • '04' : Stake (The method will be supported later.)

    • '08' : Delegate (The method will be supported later)

Requirements

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

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

    • near token: version 2.27.1 or higher is required.

Useage

const {connect, utils, providers} = require('near-api-js')
const nearTransaction = require('near-api-js/lib/transaction')
const nearSerialize = require('borsh')

const connectionConfig = {
  networkId: "mainnet",
  nodeUrl: "https://rpc.mainnet.near.org",
};
const nearConnection = await connect(connectionConfig);

let nonceOfAccessKey = await nearConnection.connection.provider.query({
    request_type: 'view_access_key_list',
    account_id: address,
    finality: 'final'
  })

const blockHash = await nearConnection.connection.provider.block({ finality: 'final' }).then(block => {
    const encodedBlockHash = block.header.hash
    return Buffer.from(bs58Lib.decode(encodedBlockHash))
  })
const nonce = ++nonceOfAccessKey;
const publicKey = utils.PublicKey.from(bs58Lib.encode(Buffer.from(address, 'hex')))
var actions = [nearTransaction.transfer(utils.parseNearAmount(BigNumber(amount).toString(10)).replace(',', ''))];

let transaction = new nearTransaction.SignedTransaction({
    transaction: {
      signerId: address,
      publicKey: publicKey,
      nonce: nonce,
      receiverId: toAddr,
      actions: actions,
      blockHash: blockHash 
    },
    signature: new nearTransaction.Signature({ 
      keyType: transaction.publicKey.keyType,
    })
  })
let unsignedTx = nearSerialize.serialize(nearTransaction.SCHEMA, transaction)

const transactionJson = {
    coinType: DcentWebConnector.coinType.NEAR,
    sigHash: unsignedTx.toString('hex'),
    path: `m/44'/397'/0'`,
    decimals, // 24
    fee, 
    symbol: 'NEAR',
    }

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

Returned response object

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