> For the complete documentation index, see [llms.txt](https://docs.dedot.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dedot.dev/ink-smart-contracts/generate-types-and-apis.md).

# Generate Types & APIs

Before interacting with a contract, you need to generate Types & APIs from the contract metadata to interact with. You can do that using `dedot` cli, this works with both [ink! ABI](https://use.ink/docs/v6/basics/abi/ink) or [Solidity ABI](https://use.ink/docs/v6/basics/abi/solidity).

```sh
dedot typink -m ./path/to/metadata.json # or metadata.contract, storage.abi

# use option -o to customize folder to put generated types
dedot typink -m ./path/to/metadata.json -o ./where/to-put/generated-types
```

After running the command, Types & APIs of the contract will be generated. E.g: if the contract's name is `flipper`, the Types & APIs will be put in a folder named `flipper`, the entry-point interface for the contract will be `FlipperContractApi` in `flipper/index.d.ts` file. An example of Types & APIs for flipper contract can be found [here](https://github.com/dedotdev/dedot/blob/main/examples/scripts/inkv5/flipper/index.d.ts).

### `ContractApi` interface

The generated `ContractApi` interface has the following structure, illustrated with an example of `FlipperContractApi` using ink! contracts using ink! ABI.

```typescript
/**
 * @name: FlipperContractApi
 * @contractName: flipper
 * @contractVersion: 6.0.0
 * @authors: Parity Technologies <admin@parity.io>
 * @language: ink! 6.0.0-alpha.3
 **/
export interface FlipperContractApi<
  ChainApi extends GenericSubstrateApi = SubstrateApi,
> extends InkGenericContractApi<ChainApi> {
  metadataType: 'ink';
  query: ContractQuery<'ink'>;
  tx: ContractTx<'ink'>;
  constructorQuery: ConstructorQuery<'ink'>;
  constructorTx: ConstructorTx<FlipperContractApi, 'ink'>;
  events: ContractEvents<'ink'>;
  storage: {
    root(): Promise<Flipper>;
    lazy(): WithLazyStorage<Flipper>;
  };

  types: {
    ChainApi: ChainApi;
    RootStorage: Flipper;
    LazyStorage: WithLazyStorage<Flipper>;
    LangError: InkPrimitivesLangError;
  };
}

```

For ink! or Solidity contracts using Sol ABI, the structure will be a bit different with some APIs are disabled. Below is an example of `ContractApi` for flipper contract using Sol ABI.

```typescript
export interface FlipperContractApi<
  ChainApi extends GenericSubstrateApi = SubstrateApi,
> extends SolGenericContractApi<Rv, ChainApi> {
  metadataType: 'sol';
  query: ContractQuery<'sol'>;
  tx: ContractTx<'sol'>;
  constructorQuery: ConstructorQuery<'sol'>;
  events: ContractEvents<'sol'>;
  constructorTx: ConstructorTx<FlipperContractApi, 'sol'>;

  types: {
    ChainApi: ChainApi;
  };
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dedot.dev/ink-smart-contracts/generate-types-and-apis.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
