> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Contracts

Register smart contracts so transactions and policies can reference them by id.

## List contracts

`GET /v1/contracts`

List of all contracts per project.
By default, a maximum of ten contracts are shown.

### Query parameters

- `limit` `integer <int32>`: Specifies the maximum number of records to return.
- `skip` `integer <int32>`: Specifies the offset for the first records to return.
- `order` `string`: Specifies the order in which to sort the results.
- `name` `string`: Specifies the name of the contract.
- `deleted` `boolean`: Specifies whether to include deleted contracts.
- `chainId` `integer <int32>`: The chain ID of the contract.
- `address` `string`: Specifies the address of the contract.

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `object` `string` _(required)_
- `url` `string` _(required)_
- `data` `object[]` _(required)_
  - `id` `string` _(required)_
  - `object` `string` _(required)_
  - `createdAt` `integer <int32>` _(required)_
  - `name` `string | null` _(required)_
  - `chainId` `integer <int32>` _(required)_: The chain ID.
  - `address` `string` _(required)_
  - `deleted` `boolean` _(required)_
  - `abi` `object[]` _(required)_
    - `name` `string`
    - `type` `string`
    - `anonymous` `boolean`
    - `payable` `boolean`
    - `constant` `boolean`
    - `stateMutability` `string`
    - `gas` `string`
    - `inputs` `object[]`
      - `name` `string`
      - `type` `string`
      - `indexed` `boolean`
      - `internalType` `unknown`
      - `components` `object[]`
    - `outputs` `object[]`
      - `name` `string`
      - `type` `string`
      - `indexed` `boolean`
      - `internalType` `unknown`
      - `components` `object[]`
  - `publicVerification` `boolean` _(required)_
- `start` `integer <int32>` _(required)_
- `end` `integer <int32>` _(required)_
- `total` `integer <int32>` _(required)_

#### `401`: Error response.

### Example request

```bash
curl 'https://api.openfort.io/v1/contracts?limit=10&skip=0&order=desc&name=NFT Contract&deleted=false&chainId=80002&address=0x742e6e61d760164d56f44801054bcf40fa821d97'
```

```ts
fetch('https://api.openfort.io/v1/contracts?limit=10&skip=0&order=desc&name=NFT Contract&deleted=false&chainId=80002&address=0x742e6e61d760164d56f44801054bcf40fa821d97')
```

## Create contract object

`POST /v1/contracts`

Add a new contract to your project in Openfort

### Request body (required) (`application/json`)

- `name` `string` _(required)_: Specifies the name of the contract (Only for display purposes).
- `chainId` `integer <int32>` _(required)_: Specifies the chain ID of the contract. Must be a [supported chain](https://www.openfort.io/docs/configuration/chains).
- `address` `string` _(required)_: Specifies the address of the contract.
- `abi` `object[]`: Specifies the ABI of the contract.
  - `name` `string`
  - `type` `string`
  - `anonymous` `boolean`
  - `payable` `boolean`
  - `constant` `boolean`
  - `stateMutability` `string`
  - `gas` `string`
  - `inputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
  - `outputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
- `publicVerification` `boolean`: Specifies whether to verify the contract publicly.

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `id` `string` _(required)_
- `object` `string` _(required)_
- `createdAt` `integer <int32>` _(required)_
- `name` `string | null` _(required)_
- `chainId` `integer <int32>` _(required)_: The chain ID.
- `address` `string` _(required)_
- `deleted` `boolean` _(required)_
- `abi` `object[]` _(required)_
  - `name` `string`
  - `type` `string`
  - `anonymous` `boolean`
  - `payable` `boolean`
  - `constant` `boolean`
  - `stateMutability` `string`
  - `gas` `string`
  - `inputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
  - `outputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
- `publicVerification` `boolean` _(required)_

#### `401`: Error response.

#### `409`: Error response.

### Example request

```bash
curl https://api.openfort.io/v1/contracts \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "NFT Contract",
  "chainId": 80002,
  "address": "0x742e6e61d760164d56f44801054bcf40fa821d97",
  "abi": [
    {
      "inputs": [
        {
          "internalType": "address",
          "name": "_owner",
          "type": "address"
        }
      ],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "stateMutability": "view",
      "type": "function"
    }
  ],
  "publicVerification": false
}'
```

```ts
fetch('https://api.openfort.io/v1/contracts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'NFT Contract',
    chainId: 80002,
    address: '0x742e6e61d760164d56f44801054bcf40fa821d97',
    abi: [
      {
        inputs: [
          {
            internalType: 'address',
            name: '_owner',
            type: 'address'
          }
        ],
        stateMutability: 'nonpayable',
        type: 'constructor'
      },
      {
        inputs: [],
        name: 'owner',
        outputs: [
          {
            internalType: 'address',
            name: '',
            type: 'address'
          }
        ],
        stateMutability: 'view',
        type: 'function'
      }
    ],
    publicVerification: false
  })
})
```

## Get a contract

`GET /v1/contracts/{id}`

Retrieve a contract by providing their contract id.

### Path parameters

- `id` `string` _(required)_: Specifies the unique contract ID (starts with con_).

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `id` `string` _(required)_
- `object` `string` _(required)_
- `createdAt` `integer <int32>` _(required)_
- `name` `string | null` _(required)_
- `chainId` `integer <int32>` _(required)_: The chain ID.
- `address` `string` _(required)_
- `deleted` `boolean` _(required)_
- `abi` `object[]` _(required)_
  - `name` `string`
  - `type` `string`
  - `anonymous` `boolean`
  - `payable` `boolean`
  - `constant` `boolean`
  - `stateMutability` `string`
  - `gas` `string`
  - `inputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
  - `outputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
- `publicVerification` `boolean` _(required)_

#### `401`: Error response.

### Example request

```bash
curl https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35
```

```ts
fetch('https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35')
```

## Updates a contract object

`POST /v1/contracts/{id}`

### Path parameters

- `id` `string` _(required)_: Specifies the unique contract ID (starts with con_).

### Request body (required) (`application/json`)

- `name` `string`: Specifies the name of the contract (Only for display purposes).
- `chainId` `integer <int32>`: Specifies the chain ID of the contract. Must be a [supported chain](https://www.openfort.io/docs/configuration/chains).
- `deleted` `boolean`: Specifies whether to delete the contract.
- `address` `string`: Specifies the address of the contract.
- `abi` `object[]`: Specifies the ABI of the contract.
  - `name` `string`
  - `type` `string`
  - `anonymous` `boolean`
  - `payable` `boolean`
  - `constant` `boolean`
  - `stateMutability` `string`
  - `gas` `string`
  - `inputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
  - `outputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
- `publicVerification` `boolean`: Specifies whether to verify the contract publicly.

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `id` `string` _(required)_
- `object` `string` _(required)_
- `createdAt` `integer <int32>` _(required)_
- `name` `string | null` _(required)_
- `chainId` `integer <int32>` _(required)_: The chain ID.
- `address` `string` _(required)_
- `deleted` `boolean` _(required)_
- `abi` `object[]` _(required)_
  - `name` `string`
  - `type` `string`
  - `anonymous` `boolean`
  - `payable` `boolean`
  - `constant` `boolean`
  - `stateMutability` `string`
  - `gas` `string`
  - `inputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
  - `outputs` `object[]`
    - `name` `string`
    - `type` `string`
    - `indexed` `boolean`
    - `internalType` `unknown`
    - `components` `object[]`
- `publicVerification` `boolean` _(required)_

#### `401`: Error response.

#### `409`: Error response.

### Example request

```bash
curl https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35 \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "NFT Contract",
  "chainId": 80002,
  "deleted": false,
  "address": "0x1234567890abcdef1234567890abcdef12345678",
  "abi": [
    {
      "inputs": [
        {
          "internalType": "address",
          "name": "_owner",
          "type": "address"
        }
      ],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "stateMutability": "view",
      "type": "function"
    }
  ],
  "publicVerification": false
}'
```

```ts
fetch('https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'NFT Contract',
    chainId: 80002,
    deleted: false,
    address: '0x1234567890abcdef1234567890abcdef12345678',
    abi: [
      {
        inputs: [
          {
            internalType: 'address',
            name: '_owner',
            type: 'address'
          }
        ],
        stateMutability: 'nonpayable',
        type: 'constructor'
      },
      {
        inputs: [],
        name: 'owner',
        outputs: [
          {
            internalType: 'address',
            name: '',
            type: 'address'
          }
        ],
        stateMutability: 'view',
        type: 'function'
      }
    ],
    publicVerification: false
  })
})
```

## Deletes a contract object

`DELETE /v1/contracts/{id}`

Delete a contract from the project by providing its contract id.

### Path parameters

- `id` `string` _(required)_: Specifies the unique contract ID (starts with con_).

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `id` `string` _(required)_
- `object` `string` _(required)_
- `deleted` `boolean` _(required)_

#### `401`: Error response.

#### `409`: Error response.

### Example request

```bash
curl https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35 \
  --request DELETE
```

```ts
fetch('https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35', {
  method: 'DELETE'
})
```

## Read on chain contract repositories

`GET /v1/contracts/{id}/read`

Using this endpoint, you can get the repositories returned by any readable
function listed in a contracts ABI. This could be things like querying
the totalSupply of a currency contract, the number of owners of an items
contract, and more.

### Path parameters

- `id` `string` _(required)_: Specifies the unique contract ID (starts with con_).

### Query parameters

- `functionName` `string` _(required)_: The function name of the contract.
- `functionArgs` `unknown[]`: The function arguments of the contract, in string format. Accepts pla_, con_ and acc_ IDs.

### Responses

#### `200`: Successful response.

Body (`application/json`):

- `id` `string` _(required)_
- `object` `string` _(required)_
- `createdAt` `integer <int32>` _(required)_
- `functionName` `string` _(required)_
- `result` `unknown` _(required)_

#### `401`: Error response.

#### `409`: Error response.

### Example request

```bash
curl 'https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35/read?functionName=mint&functionArgs=0x662D24Bf7Ea2dD6a7D0935F680a6056b94fE934d'
```

```ts
fetch('https://api.openfort.io/v1/contracts/con_0cddb398-1dc6-4e6f-8726-9ec7cea85f35/read?functionName=mint&functionArgs=0x662D24Bf7Ea2dD6a7D0935F680a6056b94fE934d')
```
