# Contract package

The `ContractPackage` entity provides a normalized representation of the Casper Network [Contract Package](https://docs.casper.network/developers/json-rpc/types_chain/#contractpackge). It includes the contract package's metadata based on Contract's type and named keys values and the latest version of the contract type within the package.

## Properties

The `ContractPackage` entity has the following properties:

| Property                          | Type                      | Description                                                                                                                                                                    |
| --------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `contract_package_hash`           | `string(64)`              | Contract package hash represented as a hexadecimal string. Unique contract package identifier                                                                                  |
| `owner_public_key`                | `string(68)`              | Public key of the owner of the contract package. May be `null` if the public key is not known, but the `owner_hash` will still be present. Represented as a hexadecimal string |
| `owner_hash`                      | `string(64)`              | Hash of the owner of the contract package. Represented as a hexadecimal string                                                                                                 |
| `name`                            | `string`                  | Name of the contract package.                                                                                                                                                  |
| `description`                     | `string`                  | Description of the contract package.                                                                                                                                           |
| `metadata`                        | `ContractPackageMetadata` | Metadata associated with the contract package. Details described in the next table.                                                                                            |
| `latest_version_contract_type_id` | `uint8`                   | [Contract type](https://docs.cspr.cloud/rest-api/contract/get-contract-types) identifier of the latest contract version                                                        |
| `timestamp`                       | `datetime`                | Timestamp indicating when the contract package was created.                                                                                                                    |
| `icon_url`                        | `string`                  | URL pointing to an icon representing the contract package.                                                                                                                     |
| `website_url`                     | `string`                  | URL pointing to the website representing the contract.                                                                                                                         |

Metadata Property:

| Metadata Property           | Type         | Description                                                                                                                                                                                    |
| --------------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`                      | `string`     | Name associated with the contract package.                                                                                                                                                     |
| `symbol`                    | `string`     | Contract package name pulled from the last version named keys. Contract package symbol pulled from the last version named keys. Applicable only for token contracts.                           |
| `decimals`                  | `uint8`      | Contract package token decimals pulled from the last version named keys. Applicable only for token contracts.                                                                                  |
| `balances_uref`             | `string(72)` | Contract package balances dictionary URef pulled from the last version named keys. Applicable only for token contracts.                                                                        |
| `total_supply_uref`         | `string(72)` | Contract package total supply URef pulled from the last version named keys. Applicable only for token contracts.                                                                               |
| `ownership_mode`            | `uint8`      | CEP-78 contract [ownership mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#ownership). Applicable only for CEP-78 contracts.                         |
| `nft_kind`                  | `uint8`      | CEP-78 contract [NFT kind](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#nftkind). Applicable only for CEP-78 contracts.                                 |
| `nft_metadata_kind`         | `uint8`      | CEP-78 contract [NFT metadata kind](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#nftmetadatakind). Applicable only for CEP-78 contracts.                |
| `whitelist_mode`            | `uint8`      | CEP-78 contract [whitelist mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#whitelistmode). Applicable only for CEP-78 contracts.                     |
| `holder_mode`               | `uint8`      | CEP-78 contract [holder mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#nftholdermode). Applicable only for CEP-78 contracts.                        |
| `minting_mode`              | `uint8`      | CEP-78 contract [minting mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#minting). Applicable only for CEP-78 contracts.                             |
| `burn_mode`                 | `uint8`      | CEP-78 contract [burn mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#burnmode). Applicable only for CEP-78 contracts.                               |
| `identifier_mode`           | `uint8`      | CEP-78 contract [identifier mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#nftidentifiermode). Applicable only for CEP-78 contracts.                |
| `metadata_mutability`       | `uint8`      | CEP-78 contract [metadata mutability mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#metadata-mutability). Applicable only for CEP-78 contracts.     |
| `owner_reverse_lookup_mode` | `uint8`      | CEP-78 contract [owner reverse lookup mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#ownerreverselookupmode). Applicable only for CEP-78 contracts. |
| `events_mode`               | `uint8`      | CEP-78 contract [events mode](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/modalities.md#eventsmode). Applicable only for CEP-78 contracts.                           |

## Optional properties

Depending on the endpoint, the following optional property may be included in the `ContractPackage` entity:

| Property            | Type                                    | Description                                                                                                                                                                                                                                        |
| ------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `deploys_number`    | `int`                                   | Number of deploys in the specified number of the past days. It's a [function includer](https://docs.cspr.cloud/documentation/overview/optional-properties#functions) that accepts the number of days as an argument.                               |
| `owner_cspr_name`   | `string`                                | Owner's primary CSPR.name                                                                                                                                                                                                                          |
| `token_market_data` | [`TokenMarketData[]`](#tokenmarketdata) | Token market data derived from indexed DEX swaps in the requested `currency`. It's a [function includer](https://docs.cspr.cloud/documentation/overview/optional-properties#functions) that accepts `currency_id` and optional `dex_id` arguments. |

**Example**

```json
{
  "contract_package_hash": "ae2feaa4e86841c1c6f40f1779e1e1cb1d9d4d52a0eb82a8962829646524e744",
  "owner_public_key": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01",
  "name": "MyContractPackage",
  "description": "A sample contract package",
  "metadata": {
    "name": "MyToken",
    "symbol": "MT",
    "decimals": 18,
    "balances_uref": "uref-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef-007",
    "total_supply_uref": "uref-abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef-007",
    "ownership_mode": 1,
    "nft_kind": 2,
    "nft_metadata_kind": 1,
    "whitelist_mode": 0,
    "holder_mode": 1,
    "minting_mode": 2,
    "burn_mode": 1,
    "identifier_mode": 0,
    "metadata_mutability": 1,
    "owner_reverse_lookup_mode": 1,
    "events_mode": 2
  },
  "latest_version_contract_type_id": 3,
  "timestamp": "2023-01-01T12:00:00Z",
  "icon_url": "https://example.com/icon.png",
  "website_url": "https://example.com",
  "deploys_number": 42
}
```

### **TokenMarketData**:

```json
{
  "dex_id": 1,
  "token_contract_package_hash": "ae2feaa4e86841c1c6f40f1779e1e1cb1d9d4d52a0eb82a8962829646524e744",
  "currency_id": 1,
  "latest_rate": 2.5,
  "volume_24h": "37.500000000000000000",
  "token_volume_24h": "15.000000000000000000",
  "timestamp": "2023-01-01T12:00:00Z"
}
```

`volume_24h` is represented in the requested currency, while `token_volume_24h` represents the raw token amount.

## Relations

The `ContractPackage` entity has the following relations with other entities:

| Entity                                                                                            | Mapping property                                                    | Description                                                                                  |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| [`Account`](https://docs.cspr.cloud/rest-api/account)                                             | `owner_hash`                                                        | Account owns the contract package                                                            |
| [`Deploy`](https://docs.cspr.cloud/rest-api/deploy)                                               | `contract_package_hash`                                             | Contracts packages are deployed to the network with a deploy call                            |
| [`Contract`](https://docs.cspr.cloud/rest-api/contract)                                           | `contract_package_hash`                                             | Contracts are different versions of the same smart contract included in the contract package |
| [`Fungible token action`](https://docs.cspr.cloud/rest-api/fungible-token-action)                 | `contract_package_hash`                                             | Occurs within the contract package that defines the fungible token                           |
| [`Fungible token ownership`](https://docs.cspr.cloud/rest-api/fungible-token-ownership)           | `contract_package_hash`                                             | Indicates which accounts own tokens from a specific contract package                         |
| [`Fungible token rate`](https://docs.cspr.cloud/rest-api/fungible-token-rate)                     | `token_contract_package_hash`                                       | Tradable fungible token have their rates tracked                                             |
| [`Fungible token daily rate`](https://docs.cspr.cloud/rest-api/fungible-token-daily-rate)         | `token_contract_package_hash`                                       | Tradable fungible token have their daily rates tracked                                       |
| [`Fungible token DEX rate`](https://docs.cspr.cloud/rest-api/fungible-token-dex-rate)             | `token_contract_package_hash`, `target_token_contract_package_hash` | Tradable fungible token pairs have their DEX rates tracked                                   |
| [`Fungible token daily DEX rate`](https://docs.cspr.cloud/rest-api/fungible-token-daily-dex-rate) | `token_contract_package_hash`, `target_token_contract_package_hash` | Tradable fungible token pairs have their daily DEX rates tracked                             |
| [`NFT action`](https://docs.cspr.cloud/rest-api/non-fungible-token-action)                        | `contract_package_hash`                                             | Takes place within the contract package that defines the NFT collection                      |
| [`NFT ownership`](https://docs.cspr.cloud/rest-api/non-fungible-token-ownership)                  | `contract_package_hash`                                             | Indicates which accounts own NFTs from a specific contract package                           |

## Endpoints

The `ContractPackage` entity has the following endpoints:

* [Get contract package](https://docs.cspr.cloud/rest-api/contract-package/get-contract-package)
* [Get contract packages](https://docs.cspr.cloud/rest-api/contract-package/get-contract-packages)

## Relation endpoints

The `ContractPackage` entity has the following relation endpoints:

* [Get contract package contracts](https://docs.cspr.cloud/rest-api/contract/get-contracts-by-contract-package)
* [Get contract package NFT tokens](https://docs.cspr.cloud/rest-api/non-fungible-token/get-contract-package-tokens) (applicable only to NFT contract packages)
* [Get contract package NFT token actions](https://docs.cspr.cloud/rest-api/non-fungible-token-action/get-contract-package-token-actions) (applicable only to NFT contract package)
* [Get contract package NFT token ownership](https://docs.cspr.cloud/rest-api/non-fungible-token-ownership/get-contract-package-token-ownership) (applicable only to NFT contract package)
* [Get contract package fungible token ownership](https://docs.cspr.cloud/rest-api/fungible-token-ownership/get-contract-package-fungible-token-ownership) (applicable only to fungible token contract package)
* [Get contract package fungible token actions](https://docs.cspr.cloud/rest-api/fungible-token-action/get-account-token-actions) (applicable only to fungible token contract package)
* [Get the latest fungible token contract rate](https://docs.cspr.cloud/rest-api/fungible-token-rate/get-latest-token-contract-rate)
* [Get historical fungible token contract rates](https://docs.cspr.cloud/rest-api/fungible-token-rate/get-token-contract-rates)
* [Get the latest daily fungible token contract rate](https://docs.cspr.cloud/rest-api/fungible-token-daily-rate/get-latest-daily-token-contract-rate)
* [Get historical daily fungible token contract rates](https://docs.cspr.cloud/rest-api/fungible-token-daily-rate/get-daily-token-contract-rates)
* [Get the latest fungible token DEX rate](https://docs.cspr.cloud/rest-api/fungible-token-dex-rate/get-latest-token-dex-rate)
* [Get historical fungible token DEX rates](https://docs.cspr.cloud/rest-api/fungible-token-dex-rate/get-token-dex-rates)
* [Get the latest fungible token daily DEX rate](https://docs.cspr.cloud/rest-api/fungible-token-daily-dex-rate/get-latest-daily-token-dex-rate)
* [Get historical fungible token daily DEX rates](https://docs.cspr.cloud/rest-api/fungible-token-daily-dex-rate/get-daily-token-dex-rates)
