The news of Telegram founder Pavel Durov’s house arrest being lifted and him being allowed to leave France prompted me to figure out how I can write an example Telegram Mini App that only relies on decentralized technologies.
After all Pavel Durov was jailed in France because (supposedly) he refuses to censor communication on Telegram, and what better way to build a censorship-resistant app than to run it on decentralized and trustless infrastructure that no single person, company or government can take down?
The following assumes that you have a front-app that relies on any of the popular front-end frameworks such as React, Vue, etc. This example is using the Vite starter app to keep things very simple. If you want to play along:
npm create vite@latest fe-app -- --template react # using React JS
cd fe-app
npm install
The Internet Computer Protocol (ICP) defines a decentralized cloud infrastructure that also supports blockchain token and cross-chain use cases – but we’re only using its cloud capabilities here to store the front-end app:
# install the Internet Computer's command-line execution environment, dfx
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
# make sure the app directory is your current directory, e.g. "fe-app" from above
# configure the app for inclusion in dfx
cat > dfx.json <<EOF
{
"canisters": {
"fe-app": {
"type": "assets",
"source": [
"dist/"
]
}
}
}
EOF
# deploy the app to ICP
dfx deploy --playground
The last command will return a URL such as this: https://mexqz-aqaaa-aaaab-qabtq-cai.icp0.io/ where your app will be available for testing for about 20 minutes. Afterwards it’s taken down, and you can deploy again to get a new URL. This is just for testing, a production deployment on ICP is a little bit more involved and I might cover this in a future article.
To complete the exercise, create a new Telegram bot and register the app URL to use your ICP app as a Telegram Mini App directly from within Telegram.
