> For the complete documentation index, see [llms.txt](https://docs.ternoa.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ternoa.network/build-1/javascript/ternoa-js-library-utilities/customs-extrinsics-and-queries.md).

# Customs extrinsics & queries

Ternoa-js provides the capability to create custom calls to the blockchain. If existing helpers do not meet your requirements, you can still perform custom operations thanks to the library's atomic architecture.

{% hint style="warning" %}
You should not have to install directly the Polkadot{js} library as the ternoa js might cover all your needs.
{% endhint %}

{% hint style="info" %}
If you are not familiar with the process of creating a transaction on the Ternoa chain, we highly suggest first reading the Getting Started section of the documentation with a focus on:&#x20;

* [The Ternoa-js architecture ](/getting-started/javascript-sdk/ternoa-js-library/architecture.md)
* [The Ternoa-js workflow](/getting-started/javascript-sdk/ternoa-js-library/workflow.md)
  {% endhint %}

If you have explored the [SDK code repository](https://github.com/capsule-corp-ternoa/ternoa-js), you would have noticed that the functions are interdependent to maintain modularity and enhance the customized usage of these functions.

### Performing a custom extrinsic transaction

Under the hood, extrinsics helpers provided on the SDK rely on this function: `createTxHex()` which creates a transaction in hex format:

```typescript
getRawApi().tx[txPallet][txExtrinsic](...txArgs)
```

&#x20;The `createTxHex()` function expects three params:&#x20;

* `txPallet` is a string corresponding to the name of the pallet. Example for an NFT mint: "nft"
* `txExtrinsic` is a string corresponding to the name of the extrinsic to execute. Example for an NFT mint: "createNft"
* `txArgs` is an optional array of arguments needed to execute the extrinsic. Example for an NFT mint: \[offchainData, royalty, collectionId, isSoulbound ]

{% hint style="info" %}
Feel free to look at the [Polkadot portal](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fmainnet.ternoa.network#/staking) to see the available queries, extrinsics, or constants and make your custom requests.
{% endhint %}

#### Example: A bridge deposit

Assuming you want to execute a transaction that is not natively proposed as a helper in the SDK, for example, a bridge deposit. Your atomic function could look like this:&#x20;

```typescript
export const bridgeDepositTx = async (
  amount: number,
  recipient: string
  destId: number,
): Promise<TransactionHashType> => {
  const formattedAmount = typeof amount === "number" ? numberToBalance(amount) : amount
  return await createTxHex("bridge, "deposit", [
    formattedAmount,
    recipient,
    destId,
  ])
}
```

or

```typescript
export const bridgeDepositTx = async (
  amount: number,
  recipient: string
  destId: number,
): Promise<TransactionHashType> => {

  const formattedAmount = typeof amount === "number" ? numberToBalance(amount) : amount
  const api = getRawApi()
  return await api.tx["bridge]["deposit"]([
    formattedAmount,
    recipient,
    destId,
  ])
}
```

### Performing a custom query

Performing custom queries works the same, except that instead of using the `createTxHex()` function, it uses the `query()`function that executes under the hood, the following code:&#x20;

```typescript
await getRawApi().query[module][call](...args)
```

&#x20;The `query()` function expects three params:&#x20;

* `module` is a string corresponding to the name of the pallet. Example to query the NFT mint fee: "nft"
* `call` is a string corresponding to the name of the call to execute. Example to query the NFT mint fee: "nftMintFee"
* `args` is an optional array of arguments needed to execute the query. Example to query the NFT mint fee: \[ ] as no argument is expected for this query. &#x20;

Same as the custom extrinsic, you can perform the desired custom query by specifying the arguments of your choice.

{% hint style="info" %}
Feel free to look at the [Polkadot portal](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fmainnet.ternoa.network#/staking) to see the available queries, extrinsics, or constants and make your custom requests.
{% endhint %}
