# @integraledger/lcp/polkadot

> The exports of @integraledger/lcp/polkadot.

Source: https://lcp.integraledger.com/reference/api/polkadot

## Interfaces

### PolkadotExtrinsic

#### Properties

| Property    | Type                 |
| ----------- | -------------------- |
|  `at`       | `object`             |
| `at.hash`   | `` `0x${string}` ``  |
| `at.height` | `bigint`             |
|  `events`   | readonly `object`\[] |
|  `hash`     | `` `0x${string}` ``  |
|  `success`  | `boolean`            |

***

### PolkadotReader

Bounded, read-only calls against one network's Sidecar. Every failure rejects.

#### Properties

| Property   | Modifier   | Type                                  |
| ---------- | ---------- | ------------------------------------- |
|  `network` | `readonly` | [`PolkadotNetwork`](#polkadotnetwork) |

#### Methods

##### extrinsic()

> **extrinsic**(`block`, `index`): `Promise`\<[`PolkadotExtrinsic`](#polkadotextrinsic) | `null`>

`GET /blocks/{block}/extrinsics/{index}`; null when the block or extrinsic does not exist.

###### Parameters

| Parameter | Type                            |
| --------- | ------------------------------- |
| `block`   | `bigint` \| `` `0x${string}` `` |
| `index`   | `number`                        |

###### Returns

`Promise`\<[`PolkadotExtrinsic`](#polkadotextrinsic) | `null`>

##### finalizedHeight()

> **finalizedHeight**(): `Promise`\<`bigint`>

`GET /blocks/head/header` → number: the most recently finalized height.

###### Returns

`Promise`\<`bigint`>

##### rawExtrinsics()

> **rawExtrinsics**(`block`): `Promise`\<readonly `` `0x${string}` ``\[] | `null`>

`GET /blocks/{block}/extrinsics-raw`; null when the block does not exist.

###### Parameters

| Parameter | Type                            |
| --------- | ------------------------------- |
| `block`   | `bigint` \| `` `0x${string}` `` |

###### Returns

`Promise`\<readonly `` `0x${string}` ``\[] | `null`>

***

### PolkadotRef

The read keys recorded at claim, computed from the signed bytes.

#### Properties

| Property         | Type                                  |
| ---------------- | ------------------------------------- |
|  `assetId`       | `number`                              |
|  `extrinsicHash` | `` `0x${string}` ``                   |
|  `network`       | [`PolkadotNetwork`](#polkadotnetwork) |

***

### PolkadotUnsigned

The call the payer's signer wraps in an extrinsic, and how that extrinsic completes the payment.

#### Properties

| Property          | Type                                  |
| ----------------- | ------------------------------------- |
|  `request`        | `object`                              |
| `request.call`    | `Uint8Array`                          |
| `request.kind`    | `"substrate-call"`                    |
| `request.network` | [`PolkadotNetwork`](#polkadotnetwork) |

#### Methods

##### complete()

> **complete**(`extrinsic`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PolkadotPaymentPayload`](#polkadotpaymentpayload)

###### Parameters

| Parameter   | Type         |
| ----------- | ------------ |
| `extrinsic` | `Uint8Array` |

###### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PolkadotPaymentPayload`](#polkadotpaymentpayload)

***

### ProfileCall

#### Properties

| Property   | Type         |
| ---------- | ------------ |
|  `amount`  | `bigint`     |
|  `assetId` | `number`     |
|  `dest`    | `Uint8Array` |
|  `remark`  | `Uint8Array` |

## Type Aliases

### PolkadotNetwork

> **PolkadotNetwork** = `"polkadot:68d56f15f85d3136970ec16946040bc1"` | `"polkadot:67f9723393ef76214df0118c34bbbd3d"`

***

### PolkadotPayload

> **PolkadotPayload** = `object`

The x402 payload: the signed extrinsic and its call, lowercase hex.

#### Properties

| Property     | Type                            |
| ------------ | ------------------------------- |
|  `call`      | [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex) |
|  `extrinsic` | [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex) |

***

### PolkadotPaymentPayload

> **PolkadotPaymentPayload** = [`X402Payment`](https://lcp.integraledger.com/reference/api/x402#x402payment)\<[`PolkadotPayload`](#polkadotpayload)>

***

### PolkadotStatus

> **PolkadotStatus** = \{ `finality`: `"finalized"` | `"head"`; `height`: `bigint`; `state`: `"settled"`; `transaction`: `string`; } | \{ `state`: `"pending"`; `why`: `"not-located"` | `"not-found"` | `"unreadable"`; } | \{ `finality`: `"finalized"` | `"head"`; `height`: `bigint`; `state`: `"failed"`; `transaction`: `string`; `why`: `"not-this-extrinsic"` | `"dispatch-failed"` | `"no-remark"` | `"no-transfer"`; }

A settlement or failure names the timepoint it read, `<block hash>-<index>`: the one given, or the canonical one when
the given block left the chain and the canonical block at that height holds the same extrinsic at that index.
Pending `not-located` asks for the payment to be located from the claim position.

## Variables

### CALL

> `const` **CALL**: `Readonly`\<\{ `batchAll`: readonly `number`\[]; `remarkWithEvent`: readonly `number`\[]; `transferKeepAlive`: readonly `number`\[]; }>

Pallet and call indices, the same on both networks.

***

### exactPolkadotRemark

> `const` **exactPolkadotRemark**: `Readonly`\<\{ `advertise`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired); `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`c`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PolkadotUnsigned`](#polkadotunsigned)>; `carrier`: `null`; `claims`: `true`; `id`: `"x402/exact/polkadot/lcp-assets-remark"`; `pattern`: [`LcpPattern`](https://lcp.integraledger.com/reference/api/x402#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](https://lcp.integraledger.com/reference/api/x402#x402read); `recover`: (`ref`, `reader`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PolkadotRef`](#polkadotref)>; `status`: (`ref`, `reader`) => `Promise`\<[`PolkadotStatus`](#polkadotstatus)>; `tie`: (`accepts`, `request`) => \[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements)\[]; `request`: [`RequestCommitment`](https://lcp.integraledger.com/reference/api/x402#requestcommitment); }]; `unplaced`: (`option`) => [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements); }>

***

### LCP\_ASSETS\_REMARK

> `const` **LCP\_ASSETS\_REMARK**: `"lcp-assets-remark"` = `"lcp-assets-remark"`

The profile's `assetTransferMethod`.

***

### POLKADOT\_NETWORKS

> `const` **POLKADOT\_NETWORKS**: readonly [`PolkadotNetwork`](#polkadotnetwork)\[]

## Functions

### decodeProfileCall()

> **decodeProfileCall**(`call`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`ProfileCall`](#profilecall)

The profile's call, exactly, with canonical compacts and no trailing byte.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `call`    | `Uint8Array` |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`ProfileCall`](#profilecall)

***

### encodeProfileCall()

> **encodeProfileCall**(`c`): `Uint8Array`

`batch_all([transfer_keep_alive(assetId, Id(dest), amount), remark_with_event(remark)])`

#### Parameters

| Parameter | Type                          |
| --------- | ----------------------------- |
| `c`       | [`ProfileCall`](#profilecall) |

#### Returns

`Uint8Array`

***

### extrinsicHash()

> **extrinsicHash**(`xt`): `` `0x${string}` ``

BLAKE2b-256 of the extrinsic's bytes, its length prefix included.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `xt`      | `Uint8Array` |

#### Returns

`` `0x${string}` ``

***

### polkadotLocate()

> **polkadotLocate**(`ref`, `reader`, `from`, `to`): `Promise`\<`string` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `null`>

Finds a payment nobody named, by hashing every extrinsic of each block from `from` to `to` (at most 256 blocks).
The first match gives its timepoint; a block that does not exist ends the scan with null.

#### Parameters

| Parameter | Type                                |
| --------- | ----------------------------------- |
| `ref`     | [`PolkadotRef`](#polkadotref)       |
| `reader`  | [`PolkadotReader`](#polkadotreader) |
| `from`    | `bigint`                            |
| `to`      | `bigint`                            |

#### Returns

`Promise`\<`string` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `null`>

***

### polkadotPairingOf()

> **polkadotPairingOf**(`o`): `"x402/exact/polkadot/lcp-assets-remark"` | `undefined`

The pairing's id for an option it can pay, or undefined.

#### Parameters

| Parameter | Type                                                             |
| --------- | ---------------------------------------------------------------- |
| `o`       | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |

#### Returns

`"x402/exact/polkadot/lcp-assets-remark"` | `undefined`

***

### polkadotRecover()

> **polkadotRecover**(`ref`, `reader`): `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>

The hash from the landed extrinsic alone, for anyone holding its timepoint: its raw bytes end with the remark call,
and the chain's record of it has the same hash, dispatched, with the `Remarked` event. Two calls.

#### Parameters

| Parameter         | Type                                                                            |
| ----------------- | ------------------------------------------------------------------------------- |
| `ref`             | \{ `network`: [`PolkadotNetwork`](#polkadotnetwork); `transaction`: `string`; } |
| `ref.network`     | [`PolkadotNetwork`](#polkadotnetwork)                                           |
| `ref.transaction` | `string`                                                                        |
| `reader`          | [`PolkadotReader`](#polkadotreader)                                             |

#### Returns

`Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>

***

### polkadotStatus()

> **polkadotStatus**(`ref`, `reader`): `Promise`\<[`PolkadotStatus`](#polkadotstatus)>

Reads the extrinsic at its timepoint `<block hash>-<index>`. It must have the recorded hash, have dispatched, and
carry the `Remarked` event for this hash's remark and a `Transferred` event of the recorded asset. A settlement and a
failure alike carry the finality of the read: `finalized` when the finalized chain holds that block, `head` when it
is above the finalized height. When the finalized chain holds another block at that height, the extrinsic at the
same index of the canonical block is read instead if its hash is the recorded one; otherwise the answer is pending
`not-located`. A block the reader does not have is pending `not-found`. A failed read, a bare broadcast hash or a
reader for another network is pending.

#### Parameters

| Parameter | Type                                     |
| --------- | ---------------------------------------- |
| `ref`     | [`PolkadotRef`](#polkadotref) & `object` |
| `reader`  | [`PolkadotReader`](#polkadotreader)      |

#### Returns

`Promise`\<[`PolkadotStatus`](#polkadotstatus)>

***

### splitSigned()

> **splitSigned**(`xt`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `end`: `number`; `signer`: `Uint8Array`; }

The preamble of a signed v4 extrinsic: the length prefix, `0x84`, `MultiAddress::Id` and a `MultiSignature`. Gives
the signer and the index after the signature; the extension bytes that follow are not decoded.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `xt`      | `Uint8Array` |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `end`: `number`; `signer`: `Uint8Array`; }

***

### ss58Decode()

> **ss58Decode**(`address`): `Uint8Array`\<`ArrayBufferLike`> | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

A simple-format SS58 address: one prefix byte 0–63, a 32-byte account, and a two-byte checksum.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `address` | `string` |

#### Returns

`Uint8Array`\<`ArrayBufferLike`> | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)
