# Class: P2P

## P2P(options)

Service class to handle interacting with the Cask P2P system

## Constructor

#### new P2P(options)

Create an instance of the P2P service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` |  | See CaskSDK configuration.

See:
  - CaskSDK

### Methods

#### (async) cancel(p2pId) → {Promise.<{tx: *}>}

Cancel a P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) create(args) → {P2P.CreateP2PResult}

Create a new P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Description
--- | --- | ---
`asset` | string | Address of asset to P2P

##### Returns:

Type
  P2P.CreateP2PResult

#### (async) estimatedCommitment(address, periodopt)

Get the estimated spend for a P2P for a specific period

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`address` | string |  |  | User address
`period` | number | <optional> | 1 month | Commitment period

#### (async) get(p2pId) → {Promise.<P2P.P2PDetail>}

Get the details of a specific P2P flow.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` |  |

See:
  - The SDK guide for more details on unit formatting at https://docs.cask.fi/developer-docs/javascript-sdk

##### Returns:

Type
  Promise.<P2P.P2PDetail>

#### (async) getUserP2PCount() → {Promise.<*>}

Get the current number of P2Ps for an address.

##### Returns:

Type
  Promise.<*>

#### (async) getUserP2PList(limitopt, offsetopt, orderByopt, orderDirectionopt) → {Promise.<*>}

Get a map of P2Ps for a specified address

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`limit` |  | <optional> | 10 | Limit
`offset` |  | <optional> | 0 | Offset
`orderBy` |  | <optional> | createdAt | Order by
`orderDirection` |  | <optional> | asc | Order direction, one of asc or desc

##### Returns:

Type
  Promise.<*>

#### (async) history(p2pId, queryoptsopt) → {Promise.<*>}

Get history for a P2P flow

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`p2pId` | string |  | P2P ID
`queryopts` |  | <optional> | Optional query options ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`limit` |  | <optional> | 10 | Limit
`offset` |  | <optional> | 0 | Offset
`orderBy` |  | <optional> | timestamp | Order by
`orderDirection` |  | <optional> | desc | Order direction, one of asc or desc
`options` |  | <optional> | asc | Optional options to pass to apollo for graphQL

##### Returns:

Type
  Promise.<*>

#### (async) init(args)

Initialize the P2P service.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`ethersConnection` | EthersConnection | <optional> | EthersConnection instance

#### (async) pause(p2pId) → {Promise.<{tx: *}>}

Pause an active P2P

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

#### (async) resume(p2pId) → {Promise.<{tx: *}>}

Resume a paused P2P.

##### Parameters:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID

##### Returns:

Type
  Promise.<{tx: *}>

### Type Definitions

#### CreateP2PResult

##### Properties:

Name | Type | Description
--- | --- | ---
`tx` | Object | Create Transaction
`chainId` | number | Chain ID that the transaction took place on
`p2pId` | string | ID of newly created P2P

#### P2PAssetDefinition

##### Properties:

Name | Type | Description
--- | --- | ---
`outputAssetSymbol` | string | Outut asset symbol

#### P2PDetail

##### Properties:

Name | Type | Description
--- | --- | ---
`p2pId` | string | P2P ID
`status` | number | P2P status
`createdAt` | number | Unix timestamp of P2P creation time