MathWallet Documentation

Welcome to the official documentation for MathWallet, your complete solution for blockchain wallet integration.

MathWallet provides powerful, easy-to-use tools for developers to connect their applications with multiple blockchain networks. This documentation covers integration methods, APIs, and resources to help you implement MathWallet in your projects.

Multi-chain Support

Integration with EVM chains, Substrate, Solana, Aptos, Sui, and more blockchains in one solution.

Web & App Integration

Comprehensive integration tools for both web dApps and native applications.

Secure Protocols

Industry-standard security protocols including SimpleWallet and WalletConnect.

BNB(BSC)

This section covers integration with Binance Smart Chain (BSC), which is an EVM-compatible blockchain network. The same integration methods can also be applied to other EVM chains like Ethereum, Arbitrum, Polygon, and Fantom.

The primary differences between these chains are the Chain ID and RPC endpoints, which can be found at:

Web Integration

Detecting the Provider

MathWallet injects an object called ethereum on the window object of any web application the user visits. The extension adds an additional isMathWallet flag to make it easy to detect MathWallet specifically.

const isMathWalletInstalled = window.ethereum && window.ethereum.isMathWallet

If MathWallet is not installed, we recommend redirecting users to our website:

const getProvider = () => {
  if ("ethereum" in window) {
    const provider = window.ethereum;
    if (provider.isMathWallet) {
      return provider;
    }
  }
  window.open("https://mathwallet.org/", "_blank");
};

Establishing a Connection

"Connecting" to MathWallet on EVM chains effectively means "to access the user's EVM account(s)":

const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];

Sending a Transaction

Once connected, your web application can send transactions with the user's permission. The process involves:

  1. Creating an unsigned transaction
  2. Having it signed by the user's MathWallet
  3. Sending it to an RPC node for processing

Below is an example of interacting with a BSC token contract:

// Example of interacting with a token contract on BSC
const tokenContractAddress = '0x6387af61fed34b021daf39d2a94a1ec6acb24444'; // Token contract address

const transactionParameters = {
  nonce: '0x00', // ignored by MathWallet
  gasPrice: '0x09184e72a000', // customizable by user during MathWallet confirmation
  gas: '0x2710', // customizable by user during MathWallet confirmation
  to: tokenContractAddress, // The token contract we want to interact with
  from: '0x7d567b1276c8b033771c462ad55d186253d2aabd', // Developer wallet address
  value: '0x00', // For token transfers, this is typically 0
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057', // Token function call data
  chainId: '0x38', // BSC mainnet chain ID
};

// txHash is a hex string
// As with any RPC call, it may throw an error
const txHash = await ethereum.request({
  method: 'eth_sendTransaction',
  params: [transactionParameters],
});

For more information about the nature of transactions on BSC and other EVM chains, please refer to BSC Developer Docs.

Signing a Message

When connected, your application can also request that the user signs a given message:

// Create a SHA3 hash of the message 'Apples'
const messageHash = web3.sha3('Owner of punk #8888');

// Signs the messageHash with a given account
const signature = await web3.eth.personal.sign(messageHash, web3.eth.defaultAccount);

WalletConnect Protocol (QR code)

WalletConnect is an open protocol for connecting desktop dApps to mobile wallets using end-to-end encryption by scanning a QR code.

Documentation: walletconnect.org

Demo: blog.mathwallet.org/?p=3361

Native dApp Integration

SimpleWallet API

For native applications, you can use the SimpleWallet protocol to open MathWallet for transaction signing:

Documentation: github.com/mathwallet/SimpleWallet

Additional Resources

Ethereum Developer Docs

ethereum.org/en/developers/docs/

Fungible Tokens

Other Libraries

Substrate (Polkadot)

Content for Substrate integration is coming soon. Please check back later for updates.

Aptos

Documentation for Aptos integration is under development. Check back soon for complete integration guides.

Sui

Sui integration documentation will be available soon. Please check back later.

Solana

Solana integration guides are currently being prepared. Please check back soon for updates.

Logos & Assets

MathWallet logos and branding assets will be available here soon.

Frequently Asked Questions

FAQ section is under development. Common questions and answers about MathWallet integration will be listed here soon.