Sure!
I did it following this tutorial, using the code in description (github) as base:
Authenticate Users With WalletConnect (Only Few Lines Of Code) - Ethereum Web3 Programming - YouTube
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://github.com/WalletConnect/walletconnect-monorepo/releases/download/1.4.1/web3-provider.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
<h1 class="title">Moralis x WalletConnect</h1>
<p id="subheader"></p>
</header>
<main>
<section class="buttons">
<button id="btn-auth">Login</button>
<button id="btn-logout">Logout</button>
<button id="btn-enable">Enable web3</button>
<button id="btn-call">Test sign call</button>
</section>
<section class="result" id="result"></section>
</main>
<!-- scripts -->
<script src="./main.js"></script>
</body>
</html>```
and main.js (excluding serverurl and appid)
/* Moralis init code */
const serverUrl = "******************************"; // My code here
const appId = "***************************************"; // My code here
Moralis.start({ serverUrl, appId });
const authButton = document.getElementById('btn-auth');
const enableButton = document.getElementById('btn-enable');
const logoutButton = document.getElementById('btn-logout');
const callButton = document.getElementById('btn-call');
const subheader = document.getElementById('subheader');
const resultBox = document.getElementById('result');
let user;
let web3;
let result = '';
const provider = 'walletconnect';
function renderApp() {
user = Moralis.User.current();
if (user) {
authButton.style.display = 'none';
logoutButton.style.display = 'inline-block';
subheader.innerText = `Welcome ${user.get('username')}`;
if (web3) {
callButton.style.display = 'inline-block';
enableButton.style.display = 'none';
} else {
callButton.style.display = 'none';
enableButton.style.display = 'inline-block';
}
} else {
authButton.style.display = 'inline-block';
callButton.style.display = 'none';
logoutButton.style.display = 'none';
subheader.innerText = '';
enableButton.style.display = 'none';
}
resultBox.innerText = result;
}
async function authenticate() {
try {
let web3;
if (provider == 'walletconnect') {
const user = await Moralis.authenticate({ provider: provider});
web3 = await Moralis.enable({ provider });
} else {
const user = await Moralis.authenticate();
web3 = await Moralis.enable();
}
} catch (error) {
console.log('authenticate failed', error);
}
renderApp();
}
async function logout() {
try {
await Moralis.User.logOut();
} catch (error) {
console.log('logOut failed', error);
}
result = '';
renderApp();
}
async function testCall() {
try {
result = await web3.eth.personal.sign('Hello world', user.get('ethAddress'));
} catch (error) {
console.log('testCall failed', error);
}
renderApp();
}
async function enableWeb3() {
try {
web3 = await Moralis.enableWeb3({ provider });
} catch (error) {
console.log('testCall failed', error);
}
renderApp();
}
authButton.onclick = authenticate;
logoutButton.onclick = logout;
callButton.onclick = testCall;
enableButton.onclick = enableWeb3;
renderApp();