# Vechain

## Sign Transaction

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

### **getVechainSignedTransaction()**

#### Supported Coin Type

* VECHAIN(VET)
* VECHAIN Token(VECHAIN\_ERC20)

#### Parameters&#x20;

* unsignedTx: unsigned hexadecimal tx [Vechain Docs](https://thorify.vecha.in/#/)
* path: key path, wallet sign with that private key with a given key path (BIP32 ex) "m/44'/818'/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: vechain or vechain token's decimals.

#### Requirements

* `D'CENT Bridge` version 1.5.0 or higher is required.
* D'CENT Biometric Wallet version 2.23.2 or higher is required.

#### Useage&#x20;

```javascript
import { thorify } from 'thorify'
import BigNumber from 'bignumber.js'
const Web3 = require("web3");		// Recommend using require() instead of import here
const web3 = thorify(new Web3(), 'http://localhost:8669')

//https://github.com/vechain/thorify/blob/72988996cead74f9c73e38860c2e055ca35a108e/src/extend/accounts.ts#L12

let clauses = {
    from: recvAddress,
    to: toAddr,
    value: DcentWebConnector.unitConverter(amount, decimals).num.toString(),
    gas
}
let rawData = await web3.eth.accounts.signTransaction(clauses, VechainConfig.DummyKey)
rawData = rawData.rawTransaction.substr(0, rawData.rawTransaction.length - 134).slice(2)

let rawBuf = Buffer.from(rawData, 'hex')
let length  = rawData.length / 2
let adjustedRaw = ''  
let size = 0

if (rawBuf[0] < 0xc0) {
  adjustedRaw = null
}

if (rawBuf[0] <= 0xf7) {
  adjustedRaw = rawData.slice(2)
} else if (rawBuf[0] <= 0xff) {
  switch (rawBuf[0] - 0xf7) {
    case 1: 
      size = 1
      break
    case 2:
      size = 2
      break
    default:
      adjustedRaw = null
  }
  adjustedRaw = rawData.slice(2 + (size * 2))
} else {
  adjustedRaw = null  
}

length = adjustedRaw.length / 2
if (length < 56) {
  adjustedRaw = (0xc0 + length).toString(16) + adjustedRaw
} else if (length < 256) {  
  adjustedRaw = '0xf8' + (length).toString(16) + adjustedRaw
} else {
  adjustedRaw = '0xf9' + (length).toString(16) + adjustedRaw
}

const transactionJson = {
    coinType: DcentWebConnector.coinType.VECHAIN,
    sigHash: adjustedRaw.slice(2),
    path: `m/44'/818'/0'/0/0`,
    decimals, // 18
    fee: fee, 
    symbol: 'VET',
}

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

#### Returned response object

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-docs.dcentwallet.com/dcent-biometric-wallet-for-pc/dcent-web-connector/vechain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
