# @integraledger/lcp/tvm

> The exports of @integraledger/lcp/tvm.

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

## Interfaces

### TonCell

A TON cell, as `@ton/core`'s `Cell` gives one: its data bits, its references and its representation hash. The entry
point's public types name this shape rather than the optional peer's class, and a `Cell` is one.

#### Properties

| Property      | Modifier   | Type                              |
| ------------- | ---------- | --------------------------------- |
|  `bits`       | `readonly` | `object`                          |
| `bits.length` | `readonly` | `number`                          |
|  `refs`       | `readonly` | readonly [`TonCell`](#toncell)\[] |

#### Methods

##### hash()

> **hash**(`level?`): `Uint8Array`

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `level?`  | `number` |

###### Returns

`Uint8Array`

***

### TonTx

A transaction as a TON Center v3 endpoint reports it. `inBody` is the inbound message body as a BoC.

#### Properties

| Property    | Type                                       |
| ----------- | ------------------------------------------ |
|  `aborted`  | `boolean`                                  |
|  `account`  | `string`                                   |
|  `finality` | `0` \| `1` \| `2`                          |
|  `hash`     | `string`                                   |
|  `inBody`   | `Uint8Array`\<`ArrayBufferLike`> \| `null` |
|  `outMsgs`  | readonly `object`\[]                       |

***

### TvmChoice

#### Properties

| Property          | Type                                                             | Description                                                                                       |
| ----------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|  `accepted`       | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) | -                                                                                                 |
|  `attachNanotons` | `bigint`                                                         | The value attached to the outgoing message, above `forwardTonAmount`.                             |
|  `jettonWallet`   | `string`                                                         | The payer's Jetton wallet for `asset`, raw (`get_wallet_address` on the master).                  |
|  `now`            | `number`                                                         | Seconds since the epoch.                                                                          |
|  `required`       | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)         | -                                                                                                 |
|  `seqno`          | `number`                                                         | -                                                                                                 |
|  `stateInit?`     | `string` \| [`TonCell`](#toncell)                                | The wallet's state init, for a wallet not yet deployed: a cell, or a base64 BoC of one root cell. |
|  `wallet`         | `string`                                                         | The payer's W5 wallet, raw.                                                                       |
|  `walletId`       | `number`                                                         | `get_subwallet_id`.                                                                               |

***

### TvmReader

Bounded, read-only calls against one network's TON Center v3 endpoint. Every failure rejects with `ReaderError`.

#### Properties

| Property   | Modifier   | Type                  |
| ---------- | ---------- | --------------------- |
|  `network` | `readonly` | `` `tvm:${number}` `` |

#### Methods

##### byHash()

> **byHash**(`txHash`): `Promise`\<[`TonTx`](#tontx) | `null`>

GET /api/v3/transactions?hash=…

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `txHash`  | `string` |

###### Returns

`Promise`\<[`TonTx`](#tontx) | `null`>

##### byInBody()

> **byInBody**(`bodyHash`): `Promise`\<readonly [`TonTx`](#tontx)\[]>

GET /api/v3/transactionsByMessage?body\_hash=…\&direction=in

###### Parameters

| Parameter  | Type                |
| ---------- | ------------------- |
| `bodyHash` | `` `0x${string}` `` |

###### Returns

`Promise`\<readonly [`TonTx`](#tontx)\[]>

##### byInMessage()

> **byInMessage**(`msgHash`): `Promise`\<readonly [`TonTx`](#tontx)\[]>

GET /api/v3/transactionsByMessage?msg\_hash=…\&direction=in

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `msgHash` | `string` |

###### Returns

`Promise`\<readonly [`TonTx`](#tontx)\[]>

##### headUtime()

> **headUtime**(): `Promise`\<`number`>

GET /api/v3/masterchainInfo: the last indexed block's gen\_utime.

###### Returns

`Promise`\<`number`>

***

### TvmRef

The read keys recorded at claim.

#### Properties

| Property            | Type                  |
| ------------------- | --------------------- |
|  `jettonWallet`     | `string`              |
|  `network`          | `` `tvm:${number}` `` |
|  `transferBodyHash` | `` `0x${string}` ``   |
|  `validUntil`       | `number`              |

***

### TvmUnsigned

#### Properties

| Property       | Type         | Description                                                             |
| -------------- | ------------ | ----------------------------------------------------------------------- |
|  `request`     | `object`     | The 32-byte representation hash of the W5 request the wallet key signs. |
| `request.hash` | `Uint8Array` | -                                                                       |
| `request.kind` | `"ton-w5"`   | -                                                                       |

#### Methods

##### complete()

> **complete**(`signature`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`TvmPayment`](#tvmpayment)

Takes the 64-byte Ed25519 signature.

###### Parameters

| Parameter   | Type         |
| ----------- | ------------ |
| `signature` | `Uint8Array` |

###### Returns

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

## Type Aliases

### TvmNetwork

> **TvmNetwork** = `` `tvm:${number}` ``

tvm:\<global\_id>: tvm:-239 mainnet, tvm:-3 testnet.

***

### TvmPayment

> **TvmPayment** = [`X402Payment`](https://lcp.integraledger.com/reference/api/x402#x402payment)\<\{ `asset`: `string`; `settlementBoc`: `string`; }>

***

### TvmStatus

> **TvmStatus** = \{ `finality`: `"confirmed"` | `"finalized"`; `state`: `"settled"`; } | \{ `state`: `"pending"`; `why`: `"not-found"` | `"in-flight"` | `"not-final"` | `"unreadable"`; } | \{ `state`: `"failed"`; `why`: `"aborted"` | `"no-transfer"` | `"bounced"` | `"expired"`; }

## Variables

### exactTvm

> `const` **exactTvm**: `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) | [`TvmUnsigned`](#tvmunsigned)>; `carrier`: `"extra.forwardPayload"`; `claims`: `boolean`; `id`: `"x402/exact/tvm"`; `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) | [`TvmRef`](#tvmref)>; `status`: (`ref`, `reader`) => `Promise`\<[`TvmStatus`](#tvmstatus)>; `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); }]; `txId`: (`tx`) => `string`; `unplaced`: (`option`) => [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements); }>

***

### OP

> `const` **OP**: `object`

#### Type Declaration

| Name                | Type         | Default value |
| ------------------- | ------------ | ------------- |
|  `internalSigned`   | `1936289396` | `0x73696e74`  |
|  `internalTransfer` | `395134233`  | `0x178d4519`  |
|  `jettonTransfer`   | `260734629`  | `0x0f8a7ea5`  |
|  `sendMsg`          | `247711853`  | `0x0ec3c86d`  |

## Functions

### lcpComment()

> **lcpComment**(`h`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`TonCell`](#toncell)

TEP-74's text comment: 32 zero bits, then the UTF-8 of the hash's LCP string. A value that is not a 32-byte hash is
`x402/payload-malformed`.

#### Parameters

| Parameter | Type                |
| --------- | ------------------- |
| `h`       | `` `0x${string}` `` |

#### Returns

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

***

### pairingOf()

> **pairingOf**(`option`): `"x402/exact/tvm"` | `undefined`

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

#### Parameters

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

#### Returns

`"x402/exact/tvm"` | `undefined`

***

### tvmCarrier()

> **tvmCarrier**(`settlementBoc`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `h`: `` `0x${string}` ``; `jettonWallet`: `string`; `payload`: [`TonCell`](#toncell); `transferBodyHash`: `` `0x${string}` ``; `validUntil`: `number`; }

Reads the signed request in a settlement BoC: an internal message whose body is a W5 `internal_signed` request with
exactly one `action_send_msg` behind an empty list, carrying a Jetton transfer whose forward payload is a reference
to a text comment holding an LCP string.

#### Parameters

| Parameter       | Type     |
| --------------- | -------- |
| `settlementBoc` | `string` |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `h`: `` `0x${string}` ``; `jettonWallet`: `string`; `payload`: [`TonCell`](#toncell); `transferBodyHash`: `` `0x${string}` ``; `validUntil`: `number`; }

***

### tvmRecover()

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

Recovers the hash from the payer Jetton wallet's transaction: the comment in its inbound Jetton transfer. One call.

#### Parameters

| Parameter         | Type                                                            |
| ----------------- | --------------------------------------------------------------- |
| `ref`             | \{ `network`: `` `tvm:${number}` ``; `transaction`: `string`; } |
| `ref.network`     | `` `tvm:${number}` ``                                           |
| `ref.transaction` | `string`                                                        |
| `reader`          | [`TvmReader`](#tvmreader)                                       |

#### Returns

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

***

### tvmStatus()

> **tvmStatus**(`ref`, `reader`): `Promise`\<[`TvmStatus`](#tvmstatus)>

Finds the transfer by its body hash on the payer's Jetton wallet, then follows its `internal_transfer` to the
payee's Jetton wallet. Settled when both executed without aborting, at the lower finality of the two. A
transaction on any other account is ignored. A failed read, or a reader for another network, is pending.

#### Parameters

| Parameter | Type                      |
| --------- | ------------------------- |
| `ref`     | [`TvmRef`](#tvmref)       |
| `reader`  | [`TvmReader`](#tvmreader) |

#### Returns

`Promise`\<[`TvmStatus`](#tvmstatus)>

***

### tvmTxId()

> **tvmTxId**(`tx`): `string`

A TON transaction hash in one spelling: lowercase hex without `0x` (x402's TON scheme gives `transaction` as
"Transaction hash (64-character hex string)"), whether it is given in hex, or in the base64 or base64url of its 32
bytes that TON Center answers. Any other string is returned unchanged.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `tx`      | `string` |

#### Returns

`string`
