Start a new dapp
Last updated
Was this helpful?
Last updated
Was this helpful?
create-typink
cliTypink comes with a cli to help you start a new project from scratch faster & easier, to create a new project, simply run the below command:
Follows the instructions, the cli will help you generate a starter & working project ready for you to start integrate your own contracts and build your own logic:
After initialize the project, you can now spin up the development server with the following command:
The generated project consists of 2 main packages:
contracts
: ink! contract artifacts & generated types
contracts/artifacts
: ink! contract artifacts (.wasm, .json or .contract file), this is where you put your contract artifacts here.
ui
: Main UI project, a React-based client.
Before interacting with your contracts, we need a few more steps to setup & register your contract deployments to Typink.
contracts/artifacts
folderContract artifacts consists of a contract metadata file (.json), a contract wasm file (.wasm) and a .contract file (metadata + wasm). After you compiled your contracts, a good practice is to copy the artifacts to contracts/artifacts
folder of the project. You'll only need the metadata file to interact with your deployed contracts, but we recommend keeping other files (.wasm, .contract) in the same place for tracking purposes.
You will get a Subtrated-based address for the contracts once you successfully deployed them to the networks.
Now we need to generate Typescript bindings for your contracts from the metadata files, Typink later can leverage these Typescript bindings to enable auto-suggestions/IntelliSense when you interact with your contracts. This is an important step that help you confidently interact with your contracts.
After running the commands, the types will generated into the contracts/types
folder. You'll get the top-level type interface for greeter
& psp22
contracts as: GreeterContractApi
and Psp22ContractApi
.
Typink needs to know your contract deployments information (address, metadata, ...) to help you do the magic under the hood. The ContractDeployment
interface have the following structure:
We'll put your contract deployments information in file: contract/deployments.ts
so you can easily manage them. Each of your contract will be given an unique id (string
), so it will be easier later when you want refer to which contract you want to interact with.
Now after registering your contract deployments, you're now ready to interact with the contracts.
Contract
instance using useContract
hookTo interact with a contract, we first need to initialize a Contract
instance using the unique ContractId
we registered in the contracts/deployments.ts
file.
useContractQuery
hookWe now can send a query message to the contract using the useContractQuery
hook.
useContractTx
hookuseWatchContractEvent
hookLeveraging powerful Dedot's type system, you can also listen to contract events easily & confidently.
Let's listen to the Greeted
event from the greeter
contract emitted once you set the message.
useDeployerTx
hookInstantiate a ContractDeployer
instance to deploy Greeter contract using useDeployer
hook and deploying the contract using useDeployerTx
hook.
Please note that yarn
is the current default package manager for the start project, make sure to on your machine to streamline the development process.
contracts/types
: Typescript bindings for each ink! contract, these can be generated through
You have several options to deploy your ink! contracts to, please checkout the list to find the network that you refer to deploy your contracts.
Follow the here to deploy your contract via . You can also deploy the contracts via , but we recommend using an UI like as a friendly & intuiative approach.
You can generate the Typescript binding using , we will put these types in contracts/types
folder. Let's generate types for greeter
& psp22
contracts
Send a message to update the greeting message using useContractTx
hook. We can also use the utility method to showing a notification about the transaction process.