Web2 connects web3

Hi,
I‘m looking for an example where I can learn how I can connect a web2 html/javascript application hosted on a tradition webserver with a motoko backend canister.

2 Likes

There might be a more complete example someone can link, but you will likely have to have your Motoko backend canister at least answer HTTP requests. Here’s an example of that:

Hopefully this helps!

1 Like

This is a good one which I started with.

Frontend uses nextjs which can be deployed on Vercel.
Backend is written with motoko running in canister

1 Like

Here is a brand new (soon to be official) starter project for Vite + React + Motoko which includes live reloading for both the frontend and backend using the Motoko Dev Server. Although this template is a work in progress, it could be useful as a reference point for setting up a Vite frontend with a Motoko canister backend.

If you want to host the frontend on an external service such as Vercel or Netlify, you’ll want to configure the IC HTTP agent to use http://localhost:4943 for your local replica or https://ic0.app for the mainnet. Here’s a code example for reference, although it’s using an outdated version of dfx (which originally used port 8000 instead of 4943).

Hopefully these links will help get you started, and I’ll let you know if I come across anything else that could be useful.

4 Likes

Many thanks for all the answers. I‘ll give them a try.

1 Like

which includes live reloading for both the frontend and backend using the Motoko Dev Server.

wow that sounds awesome! will it be possible to turn this into a general starter to provide other bundlers & frameworks to chose from a cli?

That’s the eventual plan (especially to include starting points for Next.js and Create React App).

1 Like