# @integraledger/lcp/near

> The exports of @integraledger/lcp/near.

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

## Interfaces

### NearChoice

#### Properties

| Property          | Type                                                             | Description                              |
| ----------------- | ---------------------------------------------------------------- | ---------------------------------------- |
|  `accepted`       | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) | -                                        |
|  `accessKeyNonce` | `bigint`                                                         | `view_access_key`'s nonce for the key.   |
|  `finalHeight`    | `bigint`                                                         | `block` at finality "final": its height. |
|  `payer`          | `string`                                                         | -                                        |
|  `publicKey`      | `string`                                                         | `ed25519:…` or `secp256k1:…`.            |
|  `required`       | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)         | -                                        |

***

### NearOutcome

#### Properties

| Property    | Type                                                                                                   | Description               |
| ----------- | ------------------------------------------------------------------------------------------------------ | ------------------------- |
|  `delegate` | \{ `argsBase64`: `string`; `nonce`: `bigint`; `publicKey`: `string`; `senderId`: `string`; } \| `null` | -                         |
|  `receipts` | readonly `object`\[]                                                                                   | -                         |
|  `status`   | `string`                                                                                               | `final_execution_status`. |

***

### NearReader

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

#### Properties

| Property    | Modifier   | Type                          | Description                                         |
| ----------- | ---------- | ----------------------------- | --------------------------------------------------- |
|  `network`  | `readonly` | [`NearNetwork`](#nearnetwork) | -                                                   |
|  `relayers` | `readonly` | readonly `string`\[]          | The facilitator's `/supported` `signers["near:*"]`. |

#### Methods

##### accessKeyNonce()

> **accessKeyNonce**(`account`, `publicKey`): `Promise`\<`bigint` | `null`>

`view_access_key` at "final": the key's nonce; null: no such key.

###### Parameters

| Parameter   | Type     |
| ----------- | -------- |
| `account`   | `string` |
| `publicKey` | `string` |

###### Returns

`Promise`\<`bigint` | `null`>

##### finalHeight()

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

`block` at finality "final": its header's height.

###### Returns

`Promise`\<`bigint`>

##### txStatus()

> **txStatus**(`txHash`, `sender`): `Promise`\<[`NearOutcome`](#nearoutcome) | `null`>

`EXPERIMENTAL_tx_status` with `wait_until` "NONE"; null: unknown.

###### Parameters

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

###### Returns

`Promise`\<[`NearOutcome`](#nearoutcome) | `null`>

***

### NearRef

The read keys recorded at claim, JSON-serialisable: `nonce` and `maxBlockHeight` are decimal strings. `transaction` is
added when the facilitator names it.

#### Properties

| Property          | Type                          |
| ----------------- | ----------------------------- |
|  `asset`          | `string`                      |
|  `maxBlockHeight` | `string`                      |
|  `network`        | [`NearNetwork`](#nearnetwork) |
|  `nonce`          | `string`                      |
|  `payer`          | `string`                      |
|  `publicKey`      | `string`                      |
|  `transaction?`   | `string`                      |

***

### NearUnsigned

#### Properties

| Property       | Type              | Description                                                          |
| -------------- | ----------------- | -------------------------------------------------------------------- |
|  `request`     | `object`          | SHA-256 of the NEP-461-prefixed delegate action: what the key signs. |
| `request.hash` | `Uint8Array`      | -                                                                    |
| `request.kind` | `"near-delegate"` | -                                                                    |

#### Methods

##### complete()

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

Takes the key type (0 Ed25519, 1 secp256k1) and its 64- or 65-byte signature.

###### Parameters

| Parameter           | Type                                               |
| ------------------- | -------------------------------------------------- |
| `signature`         | \{ `bytes`: `Uint8Array`; `keyType`: `0` \| `1`; } |
| `signature.bytes`   | `Uint8Array`                                       |
| `signature.keyType` | `0` \| `1`                                         |

###### Returns

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

## Type Aliases

### NearNetwork

> **NearNetwork** = `"near:mainnet"` | `"near:testnet"`

x402's NEAR network identifiers.

***

### NearPayment

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

***

### NearStatus

> **NearStatus** = \{ `finality`: `"final"` | `"optimistic"`; `state`: `"settled"`; } | \{ `state`: `"pending"`; `why`: `"not-found"` | `"in-flight"` | `"unreadable"`; } | \{ `state`: `"failed"`; `why`: `"not-this-instrument"` | `"transfer-failed"`; }

## Variables

### exactNear

> `const` **exactNear**: `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) | [`NearUnsigned`](#nearunsigned)>; `carrier`: `null`; `claims`: `boolean`; `id`: `"x402/exact/near"`; `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) | [`NearRef`](#nearref)>; `status`: (`ref`, `reader`) => `Promise`\<[`NearStatus`](#nearstatus)>; `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); }>

***

### FT\_TRANSFER\_GAS

> `const` **FT\_TRANSFER\_GAS**: `30000000000000n` = `30_000_000_000_000n`

***

### NEP461\_DELEGATE

> `const` **NEP461\_DELEGATE**: `1073742190` = `1073742190`

The NEP-461 prefix for a delegate action: (1 \<\< 30) + 366.

## Functions

### ftTransferArgs()

> **ftTransferArgs**(`payTo`, `amount`, `h`): `Uint8Array`\<`ArrayBufferLike`> | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

`ft_transfer`'s arguments: `receiver_id`, `amount` and `memo`, in that order, as `JSON.stringify` writes them. A value
that is not a 32-byte hash is `x402/payload-malformed`.

#### Parameters

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

#### Returns

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

***

### nearCarrier()

> **nearCarrier**(`signedDelegateAction`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `asset`: `string`; `h`: `` `0x${string}` ``; `maxBlockHeight`: `bigint`; `nonce`: `bigint`; `payer`: `string`; `publicKey`: `string`; }

Reads a base64 `SignedDelegateAction` whose one action is a `FunctionCall` of `ft_transfer` with a JSON object of
arguments whose `memo` is an LCP string. The bytes must be exactly the borsh encoding of what is read.

#### Parameters

| Parameter              | Type     |
| ---------------------- | -------- |
| `signedDelegateAction` | `string` |

#### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `asset`: `string`; `h`: `` `0x${string}` ``; `maxBlockHeight`: `bigint`; `nonce`: `bigint`; `payer`: `string`; `publicKey`: `string`; }

***

### nearLapsed()

> **nearLapsed**(`ref`, `reader`): `Promise`\<`boolean`>

True only when the delegate action can never execute: the final height is past `maxBlockHeight` and the key's
nonce is below the action's, or the key is gone. Two calls; a failed read is false.

#### Parameters

| Parameter | Type                        |
| --------- | --------------------------- |
| `ref`     | [`NearRef`](#nearref)       |
| `reader`  | [`NearReader`](#nearreader) |

#### Returns

`Promise`\<`boolean`>

***

### nearRecover()

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

Recovers the hash from the settlement transaction: the `memo` in its delegated `ft_transfer` arguments.

#### Parameters

| Parameter         | Type                                                                    |
| ----------------- | ----------------------------------------------------------------------- |
| `ref`             | \{ `network`: [`NearNetwork`](#nearnetwork); `transaction`: `string`; } |
| `ref.network`     | [`NearNetwork`](#nearnetwork)                                           |
| `ref.transaction` | `string`                                                                |
| `reader`          | [`NearReader`](#nearreader)                                             |

#### Returns

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

***

### nearStatus()

> **nearStatus**(`ref`, `reader`): `Promise`\<[`NearStatus`](#nearstatus)>

Finds the relayed transaction under each published relayer (at most four), then requires its delegate to be this
instrument and reads the receipts the token contract executed: a failure is failed, a success is settled. A
failed read, an empty relayer list, or a reader for another network is pending.

#### Parameters

| Parameter | Type                             |
| --------- | -------------------------------- |
| `ref`     | [`NearRef`](#nearref) & `object` |
| `reader`  | [`NearReader`](#nearreader)      |

#### Returns

`Promise`\<[`NearStatus`](#nearstatus)>

***

### pairingOf()

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