Skip to main content

Intro

mq-web3 snap provides more possibilities for building web3 social dapps

You can familiarize yourself with mq-web3 snap based on the following example

Before starting, you need to install the flask plugin on your browser. After the plugin is installed, execute the following code in your dapp to install the mq-web3 snap

Installation

const connect = async function () {
await window.ethereum.request({
method: "wallet_enable",
params: [
{
wallet_snap: {
["npm:web3-mq-snaps"]: {
version: "^1.0.6",
},
},
},
],
});
};
connect();

Methods

nametypeParameters Descriptionresponse
creatRoomfunction1.group_name?: string 2. avatar_url ?: stringObject: Web3-MQ Client
queryChannelListfunction1. options: PageParamsPromise: activechanneltype[]
getTargetUserIdfunction1. address: stringPromise: searchusersresponse
sendMessagefunction1. msg: string 2. topic : stringPromise: void
getMessageListfunction1. options: PageParams 2.topic: stringPromise: messagelistitem[]
sendNotifyMessagefunction1. message: stringPromise: void

Usage

Execute command Let snap execute logic in ESE and return the return value to you

const sendMessage = async function () {
const msg = "Hello snaps";
const topic = "user:daeb1886610c47430790cf1f20cba93936d418adba5857e678210c40"; // web3mq's userid
try {
const res = await ethereum.request({
method: "wallet_invokeSnap",
params: [
"npm:web3-mq-snaps",
{
method: "sendMessage",
params: { msg, topic },
},
],
});
console.log("res", res);
if (!res) return;
return res;
} catch (err) {
console.error(err);
alert(`Problem happened: ${err.message}` || err);
}
};
sendMessage();