Multiplayer Metaverse Creation on Ethereum
Tags: webxr, ethereum, aws, threejs
Published: 2023-07-02 12:23:28

---
title: Multiplayer Metaverse Creation on Ethereum
published: true
date: 2023-07-02 12:13:59 UTC
tags: webxr,ethereum,aws,threejs
canonical_url: https://jamesmiller.blog/how-to-build-a-multi-user-metaverse/
---

### How to create a serverless Metaverse with Solidity, Lambda, API Gateway, React Three Fiber, DynamoDB and Metamask.

![](https://cdn-images-1.medium.com/max/1024/1*6SweJHt7pNpZ4w-ODLIV8A.jpeg)

### Intro​

The word Metaverse has been thrown around a lot and it can be quite confusing to actually understand what it means.

I’ve [previously created a post that explains what the term ‘metaverse’ means](https://jamesmiller.blog/what-is-the-metaverse/), in this blog post I want to talk through the steps on how to build a Metaverse — like this one

![](https://cdn-images-1.medium.com/max/600/1*-WpPhrAiWdiraU363BWD9Q.gif)

This demo is a combination of the [WebXR](https://jamesmiller.blog/wrapperjs-webxr-template/) and [Web3 log-in](https://jamesmiller.blog/wrapperjs-eth-auth-template/) codebases I’ve previously created.

If you want to follow along with this, it is my strong recommendation that you read through the [WebXR](https://jamesmiller.blog/how-to-make-real-time-multiplayer-webxr-experiences-part-1/) and [Web3 log-in](https://jamesmiller.blog/how-to-set-up-auth-with-metamask-using-amazon-cognito-part-1/) blog posts I’ve created, as a lot of the content in this post is built on top of them.

If you want to skip all this and try out getting started with building a metaverse using a template I’ve created, you can have a [play with that here](https://jamesmiller.blog/wrapperjs-eth-metaverse-template/)!

LETS JUMP IN :D

### The theory behind building a Metaverse​

In this section I’ll explain the theory behind how building a Metaverse can work, by talking through the concept, tech stack and app flow!

### Concept​

![](https://cdn-images-1.medium.com/max/1024/1*VVEm2qxMxB77pLq2GkuMQQ.jpeg)

The demo I’ve created essentially works as follows:

1. The users who want to use the Metaverse log in to the web page using their Metamask wallets ([see this blog post](https://jamesmiller.blog/how-to-set-up-auth-with-metamask-using-amazon-cognito-part-1/) for details on how that works)
2. Once logged in, those users can interact with other users through the use of websockets ([see this blog post](https://jamesmiller.blog/how-to-make-real-time-multiplayer-webxr-experiences-part-1/) for further details)
3. Those users can then interact with smart contracts on the Ethereum blockchain via the use of their Metamask wallets

### The Tech Stack​

![](https://cdn-images-1.medium.com/max/1024/1*cDfzafplN43BJB-MOigrzw.jpeg)

I’ve summarised the technologies used to create the Metaverse demo as:

**Infrastructure**

I use Terraform to create all cloud resources on AWS excluding Lambda functions that run business logic.

**Back End**

Serverless Framework is used to create Node.JS lambda functions, which interact with the Ethereum network via Web3.js and with the AWS resources that generate credentials for authenticated users. The Back End also implements Websockets using API Gateway.

**Blockchain**

I’ve used Ethereum related technologies such as Solidity and Hardhat for the smart contract creation / deployment, Web3.js is a core technology in the stack that lets the Back End and Front End interact with Smart Contracts.

**Front End**

Next.js a React.js framework that contains the logic for the Three.js library that generates the 3D environment in WebGL.

### The App Flow​

![](https://cdn-images-1.medium.com/max/1024/1*ZGhD57Z6AvcLWUuwZvJXjw.jpeg)

This app flow is a mix between the [Web3 Auth](https://jamesmiller.blog/how-to-set-up-auth-with-metamask-using-amazon-cognito-part-1/) and the [WebXR multiplayer](https://jamesmiller.blog/how-to-make-real-time-multiplayer-webxr-experiences-part-1/) blog posts that I’ve previously created.

As a summary for the Web3 Auth flow:

- A user signs a signature with their metamask wallet and submits this to AWS via the API Gateway
- A lambda function then processes the signature to verify if this has been signed by a valid user, if so it will then generate AWS STS credentials for the user to log in with
- Once logged in, the user can then interact with smart contracts and other users on the DApp

As a summary for what happens in the DApp:

- A user opens a websocket connection using the AWS credentials that they’ve been provided with from the Auth process
- This websocket broadcasts the users position in 3d space, as well as receives other users positions in that 3d space and visualises them on the users screen
- The users can then move around the environment and interact with smart contracts together in real time

### Conclusion​

I hope this post has been useful in summarising how to go about developing a Metaverse.

As this post is a cross between Web3 Auth and WebXR multiplayer experiences (both of which I have created long tutorials posts about previously), I’ve deliberately kept this one shorter.

For the full code base and instructions on how to set up, please see [this template I’ve made for Wrapper.js](https://jamesmiller.blog/wrapperjs-eth-metaverse-template/)!

Have fun :D

* * *