# @integraledger/lcp/aptos

> The exports of @integraledger/lcp/aptos.

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

## Interfaces

### AptosCommitted

A committed user transaction as the REST API returns it.

#### Properties

| Property                     | Type                 |
| ---------------------------- | -------------------- |
|  `expiration_timestamp_secs` | `string`             |
|  `hash`                      | `string`             |
|  `payload`                   | `object`             |
| `payload.arguments`          | `unknown`\[]         |
| `payload.function`           | `string`             |
| `payload.type`               | `string`             |
| `payload.type_arguments`     | `string`\[]          |
|  `sender`                    | `string`             |
|  `sequence_number`           | `string`             |
|  `success`                   | `boolean`            |
|  `type`                      | `"user_transaction"` |
|  `version`                   | `string`             |

***

### AptosInstrument

The transfer the payer signed, in one normal form shared by the signed bytes and the chain's REST answer.

#### Properties

| Property          | Type                 |
| ----------------- | -------------------- |
|  `arguments`      | readonly `string`\[] |
|  `chainId`        | `number`             |
|  `expiresAt`      | `bigint`             |
|  `function`       | `string`             |
|  `sender`         | `` `0x${string}` ``  |
|  `sequenceNumber` | `bigint`             |
|  `typeArguments`  | readonly `string`\[] |

***

### AptosPaymentPayload

#### Properties

| Property              | Type                                                             |
| --------------------- | ---------------------------------------------------------------- |
|  `accepted`           | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |
|  `extensions?`        | `object`                                                         |
|  `payload`            | `object`                                                         |
| `payload.transaction` | `string`                                                         |
|  `resource?`          | `object`                                                         |
| `resource.url`        | `string`                                                         |
|  `x402Version`        | `2`                                                              |

***

### AptosReader

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

#### Properties

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

#### Methods

##### byHash()

> **byHash**(`hash`): `Promise`\<[`AptosCommitted`](#aptoscommitted) | \{ `type`: `"pending_transaction"`; } | `null`>

`GET /v1/transactions/by_hash/{hash}`; null on 404.

###### Parameters

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

###### Returns

`Promise`\<[`AptosCommitted`](#aptoscommitted) | \{ `type`: `"pending_transaction"`; } | `null`>

##### bySequence()

> **bySequence**(`sender`, `n`): `Promise`\<[`AptosCommitted`](#aptoscommitted) | `null`>

`GET /v1/accounts/{sender}/transactions?start=n&limit=1`, kept only when its `sequence_number` is n.

###### Parameters

| Parameter | Type                |
| --------- | ------------------- |
| `sender`  | `` `0x${string}` `` |
| `n`       | `bigint`            |

###### Returns

`Promise`\<[`AptosCommitted`](#aptoscommitted) | `null`>

##### ledger()

> **ledger**(): `Promise`\<\{ `chainId`: `number`; `timestampUsecs`: `bigint`; }>

`GET /v1`.

###### Returns

`Promise`\<\{ `chainId`: `number`; `timestampUsecs`: `bigint`; }>

***

### AptosRef

#### Properties

| Property          | Type                    | Description                                     |
| ----------------- | ----------------------- | ----------------------------------------------- |
|  `expiresAt`      | `string`                | -                                               |
|  `idDigest`       | `` `0x${string}` ``     | -                                               |
|  `network`        | `` `aptos:${number}` `` | -                                               |
|  `sender`         | `` `0x${string}` ``     | -                                               |
|  `sequenceNumber` | `string`                | Decimal strings.                                |
|  `transaction?`   | `` `0x${string}` ``     | The facilitator's transaction hash, once named. |

***

### AptosUnsigned

#### Properties

| Property           | Type                                                             |
| ------------------ | ---------------------------------------------------------------- |
|  `request`         | `object`                                                         |
| `request.accepted` | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |
| `request.kind`     | `"aptos-transaction"`                                            |

#### Methods

##### complete()

> **complete**(`signed`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`AptosPaymentPayload`](#aptospaymentpayload)

###### Parameters

| Parameter            | Type                          |
| -------------------- | ----------------------------- |
| `signed`             | \{ `transaction`: `string`; } |
| `signed.transaction` | `string`                      |

###### Returns

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

## Type Aliases

### AptosNetwork

> **AptosNetwork** = `` `aptos:${number}` ``

CAIP-2: `aptos:` and the numeric chain id.

***

### AptosStatus

> **AptosStatus** = \{ `state`: `"settled"`; `transaction`: [`Hex`](https://lcp.integraledger.com/reference/api/evm#hex); `version`: `bigint`; } | \{ `state`: `"pending"`; `why`: `"not-found"` | `"in-mempool"` | `"unreadable"`; } | \{ `state`: `"failed"`; `why`: `"aborted"` | `"superseded"` | `"expired"`; }

## Variables

### exactAptos

> `const` **exactAptos**: `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`: (`choice`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`AptosUnsigned`](#aptosunsigned)>; `carrier`: `null`; `claims`: `boolean`; `id`: `"x402/exact/aptos"`; `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); `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`AptosRef`](#aptosref)>; `status`: (`ref`, `reader`) => `Promise`\<[`AptosStatus`](#aptosstatus)>; `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); }>

## Functions

### aptosIdDigest()

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

SHA-256 over the RFC 8785 form of `{sender, sequenceNumber, function, typeArguments, arguments}`.

#### Parameters

| Parameter | Type                                  |
| --------- | ------------------------------------- |
| `i`       | [`AptosInstrument`](#aptosinstrument) |

#### Returns

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

***

### aptosOptionCheck()

> **aptosOptionCheck**(`option`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `undefined`

The pairing's filter: undefined for an option this pairing can pay, or the refusal naming why not.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `option`  | `unknown` |

#### Returns

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

***

### aptosPairingOf()

> **aptosPairingOf**(`option`): `"x402/exact/aptos"` | `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/aptos"` | `undefined`

***

### aptosStatus()

> **aptosStatus**(`ref`, `reader`): `Promise`\<[`AptosStatus`](#aptosstatus)>

Finds the payer's transaction by the facilitator's hash when named, else by sender and sequence number, and
identifies it by the transfer's digest. Only `success` decides a committed, matching transaction. A failed read,
or a reader for another network, is pending. At most three calls.

#### Parameters

| Parameter | Type                          |
| --------- | ----------------------------- |
| `ref`     | [`AptosRef`](#aptosref)       |
| `reader`  | [`AptosReader`](#aptosreader) |

#### Returns

`Promise`\<[`AptosStatus`](#aptosstatus)>

***

### committedInstrument()

> **committedInstrument**(`t`, `chainId`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`AptosInstrument`](#aptosinstrument)

The REST answer in the normal form: every address as `0x` and 64 lowercase hex, `{"inner": a}` as `a`, and the
amount as its decimal string. The REST answer carries no chain id, so the caller supplies the ledger's.

#### Parameters

| Parameter | Type                                |
| --------- | ----------------------------------- |
| `t`       | [`AptosCommitted`](#aptoscommitted) |
| `chainId` | `number`                            |

#### Returns

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

***

### decodeAptosTx()

> **decodeAptosTx**(`transaction`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`AptosInstrument`](#aptosinstrument)

Reads the `RawTransaction` prefix of a base64 transaction, in either wire form: the scheme's BCS bytes, or x402's
reference form, base64 of the JSON `{"transaction": [bytes], "senderAuthenticator": [bytes]}`. Only an entry
function call to a framework fungible-asset transfer is accepted.

#### Parameters

| Parameter     | Type     |
| ------------- | -------- |
| `transaction` | `string` |

#### Returns

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