docs ⦿ dedot 🧑‍💻
TypinkXTelegramGithub
dedot 🧑‍💻
dedot 🧑‍💻
  • Welcome to Dedot
  • Why Dedot?
  • Getting started
    • Installation
    • Connect to network
    • @polkadot/api -> dedot
    • Packages structure
  • Clients & Providers
    • Providers
    • Clients
  • Client API
    • ChainApi
    • Constants
    • Runtime APIs
    • Storage Queries
    • Transactions
    • Events
    • Errors
  • ink! Smart Contracts
    • Introduction
    • Generate Types & APIs
    • Deploy contracts
    • Queries
    • Transactions
    • Storage
    • Events
    • Handle errors
    • Utilities
  • CLI
  • Keyring & Signer
  • Runtime upgrades
  • Type system
  • Utilities
    • HexString
    • Uint8Array (U8a)
    • String
    • Hash functions
    • Address
    • BigInt & number
    • Balances
    • Merkleized Metadata
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. ink! Smart Contracts

Generate Types & APIs

PreviousIntroductionNextDeploy contracts

Last updated 4 days ago

Was this helpful?

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:

dedot typink -m ./path/to/metadata.json # or metadata.contract

# 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 .

ContractApi interface

The generated ContractApi interface has the following structure, illustrated with an example of FlipperContractApi:

/**
 * @name: FlipperContractApi
 * @contractName: flipper
 * @contractVersion: 0.1.0
 * @authors: Parity Technologies <[email protected]>
 * @language: ink! 6.0.0-alpha
 **/
export interface FlipperContractApi<
  Rv extends RpcVersion = RpcVersion,
  ChainApi extends VersionedGenericSubstrateApi = SubstrateApi,
> extends GenericContractApi<Rv, ChainApi> {
  query: ContractQuery<ChainApi[Rv]>;
  tx: ContractTx<ChainApi[Rv]>;
  constructorQuery: ConstructorQuery<ChainApi[Rv]>;
  constructorTx: ConstructorTx<ChainApi[Rv]>;
  events: ContractEvents<ChainApi[Rv]>;
  storage: {
    root(): Promise<Flipper>;
    lazy(): WithLazyStorage<Flipper>;
  };

  types: {
    RootStorage: Flipper;
    LazyStorage: WithLazyStorage<Flipper>;
    LangError: InkPrimitivesLangError;
    ChainApi: ChainApi[Rv];
  };
}
here