# Home

###

## CaskSDK

CaskSDK is the primary entrypoint into the Cask SDK.
The CaskSDK class contains both static helpers and, when instantiated, automatically instantiates instances of various service classes to interact with the different parts of the Cask platform.
For details on the SDK constructor configuration object, please see the SDK guide: https://docs.cask.fi/developer-docs/javascript-sdk#configuration

Version:
  - 1.1
Author:
  - Cask Protocol & Subverse Labs, LLC

### Example

    const provider = new ethers.providers.Web3Provider(web3.currentProvider);

    const cask = new CaskSDK({
        connections: {
            rpc: {
                // rpc connections are for reading from the blockchain and should have one per chain
                [CaskSDK.chains.POLYGON_MUMBAI]: 'https://...',
            },
            ws: {
                // ws connections are for listening for events on the blockchain and should have one per chain
                [CaskSDK.chains.POLYGON_MUMBAI]: 'wss://...',
            },
            // signer connections are for sending transactions to the blockchain and can have just one
            // since it can use the browser wallet (such as Metamask) which can switch chains
            signer: provider.getSigner(),
        },
        ipfs: {
            pinataApiKey: process.env.PINATA_API_KEY,
            pinataApiSecret: process.env.PINATA_API_SECRET,
        },
        environment: CaskSDK.environments.TESTNET,
    });

    await cask.init();

### Namespaces

abi
assetIcons
chains
contracts
defaultChains
deployments
enc
environments
ipfs
units
urls
utils

### Members

#### events :Events

Events service instance.

##### Type:

- Events

#### prices :Prices

Prices service instance.

##### Type:

- Prices

#### query :Query

Query service instance.

##### Type:

- Query

#### subscriptionPlans :SubscriptionPlans

Subscription Plans service instance.

##### Type:

- SubscriptionPlans

#### subscriptions :Subscriptions

Subscriptions service instance.

##### Type:

- Subscriptions

#### vault :Vault

Vault service instance.

##### Type:

- Vault

### Methods

#### currentAddress()

Get address from signer of current connection

##### Returns:

address

#### currentChain()

Get chain ID of current connection

##### Returns:

chain ID

#### currentProvider()

Get ethers provider of current connection

##### Returns:

provider

#### currentSigner()

Get ethers signer of current connection

##### Returns:

signer

#### environment()

Get current Cask environment

##### Returns:

environment

#### (async) init(args)

Initialize the blockchain connection(s).

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | Object | Function arguments ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`ethersConnection` | EthersConnection | <optional> |  | EthersConnection instance
`chainId` | number | <optional> | options.environment | ID of chain to use
`signer` | Signer | <optional> | options.connections.signer | Signer to use on new chain.

#### signMessage(message)

Sign a message using the current connection signer

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` |  | Message to sign

##### Returns:

signature

#### stop()

Shutdown connections for background services

#### switchChain(chainId, signer)

Switch current chain

##### Parameters:

Name | Type | Description
--- | --- | ---
`chainId` |  | Chain ID
`signer` |  | Ethers signer

#### switchSigner(signer)

Switch signer of current connection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`signer` |  | signer