Skip to main content

Type and Standards

Type List

DappConnectInitParams

nametypeformatdescegdefault
dAppIDstringDappIDyour dapp idSwapChat:im-
requestTimeoutnumbermsmax request timeout180000180000
keepAlivebool-Save current connection statusfalsefalse
envstring'test' | 'dev'network environment of dappConnecttesttest
tip

KeepAlive Explain

Opened state: After initializing the client, it will automatically revert to the last connection between the wallet and the dapp.

After the connection between wallet and dapp is established, if the dapp side disconnects from the network or the websocket is disconnected due to some accident, then we will get the wallet address from the previous state and restore to your last operation.

eg: After the wallet authorization connects to the dapp, the dapp client is closed, after opening the dapp again, after initializing the client, it will automatically revert to the wallet authorization state and you can initiate a signature directly

Closed state: After initializing the client, dapp needs to request authorization with the wallet every time

initCallback()

params: DappConnectCallbackParams

DappConnectCallbackParams

nametypeformatdesceg
typeconnect | dapp-connectcallbackTypecallback type"connect" or "dapp-connect"
dataCallbackData-response body{ code: 0, message: '', approve: true }

CallbackDataType

nametypeformatdescegdefault
metadataCallbackMetedataType-metadata{ action: 'connectResponse', approve: true, result: {} }null
methodprovider_authorization | personal_sign-request methodprovider_authorizationundefined
approvebool-approve statustrue-
codenumber-status code0-
messagestring-messageconnect success-

CallbackMetedataType

nametypeformatdescegdefault
signaturestring-sign res0x00000000undefined
addressstring0x0000000wallet address0x00000000undefined
walletInfoWalletInfoType-Web3MQ wallet Info{name: 'Wallet Demo App'}undefined

DappConnectSignParams

nametypeformatdescegdefault
signContentstring-any sign messagehello-
addressstringa string of addresswallet address0x00000000-
passwordstring-sign passwordpassword''

WalletInfoType

nametypeformatdescegdefault
namestring-name of Web3Mq Wallet"Wallet Demo App"undefined

Standard List

DappConnect Callback Type

Return type of callback function

const callbackType = "connect";
// When type is connect, it means that the returned data represents the connection status of the websocket

const callbackType = "dapp-connect";
// When type is connect, it means that the data returned is the communication data representing the dapp and the wallet

web3mq deeplink

const requsetJson = {
request: {
id: 1,
jsonrpc: "2.0",
method: "provider_authorization",
params: {
requiredNamespaces: {
eip155: {
chains: ["eip155:1"],
methods: ["personal_sign"],
},
},
// `sessionProperties` is Optional
sessionProperties: {
expiry: "2022-12-24T17:07:31+00:00",
},
},
},
proposer: {
publicKey: "",
appMetadata: {
name: "",
description: "",
url: "",
icons: ["", ""],
redirect: "", // 可选
},
},
topic: "",
};


// the deeplink is requsetJson application/x-www-form-urlencoded encode to uri

const deepLink `web3mq://?request[method]=personal_sign&request[params]=hello,world!&request[id]=test_request_id&topic=test_topic_id&proposer[publicKey]=test_public_key&proposer[metadata][description]=for%20test&proposer[metadata][url]=test_url&proposer[metadata][icons][]=https://test_icon%3F1&proposer[metadata][icons][]=https://test_icon%3F2&proposer[metadata][name]=test_app&proposer[metadata][redirect]=web3mq.com`


DappConnectCallbackParams

The data correspond to some description of the situation

When the network connection is successful

const callbackData = {
type: "connect",
data: {
message: "connect success",
approve: true,
code: 0,
metadata: null,
},
};

When the wallet is successfully connected

const callbackData = {
type: "dapp-connect",
data: {
metadata: {
address: "0x54277Ee3b362C2E0eeb8D9D3aEe48840C3fD3cBd",
walletInfo: {
name: "Wallet Demo App"
}
},
approve: true,
message: "",
code: 0,
method: "provider_authorization",
},
};

When the wallet signature is successful

const callbackData = {
type: "dapp-connect",
data: {
metadata: {
signature:
"0x88cd1dd1e6a53aa6a793f3accc0838a902de00b505b433f0c207ca5e45547491539ed5b73040172e29f788c5d8782aee13e1306f531e98439a6d4e38d35c60de1b",
},
approve: true,
message: "",
code: 0,
method: "personal_sign",
},
};
tip

When the return value of approve is FALSE, it means that there is an accident in the communication between wallet and dapp, please find below the corresponding code and message

Wallet standard response

The valid error messages codes are the following:

  • When user disapproves exposing accounts to requested chains
    • code = 5000
    • message = "User disapproved requested chains"
  • When user disapproves accepting calls with the request methods
    • code = 5001
    • message = "User disapproved requested methods"
  • When user disapproves accepting calls with the request events
    • code = 5002
    • message = "User disapproved requested events"
  • When wallet evaluates requested chains to not be supported
    • code = 5100
    • message = "Requested chains are not supported"
  • When wallet evaluates requested methods to not be supported
    • code = 5101
    • message = "Requested methods are not supported"
  • When wallet evaluates requested events to not be supported
    • code = 5102
    • message = "Requested events are not supported"
  • When a badly-formed request includes a chainId mismatched to scope
    • code = 5103
    • message = "Scope/chain mismatch"
  • When a badly-formed request defines one chainId two ways
    • code = 5104
    • message = "ChainId defined in two different scopes"

wallet standard response

Code and message when network connection fails

typemethodcodemessage
connect-1Temporary connection establishment failure
connect-2Connection timeout, please try again to connect
connect-3Connection closed, please try again to connect
dapp-connectprovider_authorization4Wallet connection timeout, please try again
dapp-connectprovider_authorization5Wallet connection error, please try again
dapp-connectprovider_authorization6Wallet signature timeout, please try again
dapp-connectpersonal_sign7Signature error, please try again
dapp-connectpersonal_sign8An unknown error has occurred, please try again