Develop ink! dApp using Typink
In this tutorial, we'll guide you through the process of developing a simple ink! dApp using Typink- a new set of react hooks & utilities to help to build new ink! dApp faster & easier.
Let's make a simple PSP22 Transfer dApp using Typink!
Create a new project via create-typink CLI
create-typink CLIWe're going to set up a new ink! dapp project via the create-typinkcli.
npx create-typink@latestLet's choose greeter as example contract and deploy our contract to Pop Testnet.

We can now go to the psp22-transferfolder and run yarn startto start the development server at: http://localhost:8080

Claim testnet token via faucet
Next step, in order to deploy & interact with contracts on Pop Testnet, we'll need to claim some test token. Since Pop Testnet as a parachain uses the native token of the Relay Chain (Paseo) as its token to pay transaction fee, so it requires 2 steps to claim testnet token on Pop Testnet.
Claim PAS test token on Paseo faucet via https://faucet.polkadot.io/
Transfer PAS token from Paseo to Pop Testnet via https://onboard.popnetwork.xyz/
After you finished claiming & transfering the PAS token to Pop Testnet, let's compile & deploy our PSP22 contract.
Compile & deploy PSP22 Contract
We're using this PSP22 implementation from Cardinal-Cryptography (the team behind Aleph Zero) in this tutorials.
After cloning the repo, we can build the contract using the following commands:
After building the contract, we'll get all the compiled artifacts in folder: target/ink

Now let's copy all these 3 files into the folder: contracts/artifacts/psp22in our psp2-transferproject.

Next, let's deploy our PSP22 contract to Pop Testnet via https://ui.use.ink/

We'll fill in some basic information of the PSP22 token as below, feel free to adjust the params as to your preferences.

We deployed the contract, and its address is: 13JSR8RUSxtg11MLg2Pj5jV7Yh9sh9gCnjFW7ReHGmDj5Rvq

Finally, let's update the contract deployments list in file: contracts/deployment.ts to register our new PSP22 contract to the list, this helps us quickly initiate new Contract instance via Typink's react hooks: useContract
Generate TypeScript bindings for the contract
Next, let's generate TypeScript bindings/types for our PSP22 contract using its metadata. This helps us enable auto-complete & suggestions (IntelliSense) later when we deal & interact with contract messages / events.
We can do this via dedotcli, dedot is a required dependency and will be install for every Typink-based projects. Let's put the generated types in folder: contracts/types :
After this step, we're ready to start coding the logic for our application.

Fetch & show PSP22 balance
First, let's initiate a global Contractinstance in AppProvider (ui/src/providers/AppProvider.tsx) so we can use it across our app & components.
Next, let's fetch & show the PSP22 balance for connected account. We're going to update the MainBoardcomponent (ui/src/components/MainBoard.tsx) to add the logic using useContractQueryhook to fetch basic contract information (symbol, decimals) and psp22 balance of the connected account.
Now, after connected to the account we're using to deploy the contract, it's showing the total PSP22 balance of account.

Create a transfer form/UI
Next, let's create a transfer form which includes the following components:
Destination Address: the address that we'll transfer the token to
Amount: the amount of PSP22 token we'll send to the Destination Account
Submit Button: a button to submit the form
The UI will look like this after we added the form.

Submit transfer transaction with transaction toaster
Now, let's implement the logic make the transfer transaction using useContractTxhook:
Now, let's try it out when we transfer some PSP22 token to a different address:

You can always checkout the Github repo of this psp22-transferproject, clone & have fun!
Last updated
Was this helpful?