💳Connect to EMG Pay

If you want EMG Pay to be able to connect to your dapps, it is necessary that your dapp wallets detect EMG Pay and allow connection.

Currently, you need to contact us first to add your app to the miniapps.

EMG supports the following methods for dapp

eth_requestAccounts
eth_chainId
eth_sendTransaction
personal_sign
eth_accounts 
eth_blockNumber
eth_estimateGas
eth_getTransactionByHash
eth_getBalance
eth_call

Detect EMG Pay

if (typeof window.ethereum.isEmgPay !== "undefined") { 
    console.log("EMG Pay is installed!"); 
}

Connect to EMG Pay

 async function requestAccount() {

    if(window.ethereum.isEmgPay){
        try {
            const accounts = await window.ethereum.request({
                method: "eth_requestAccounts",
            });
            console.log(accounts)           
        } catch (error) {
            console.log(error)
        }
    }

}

Detect a user's network

const chainId = await window.ethereum
    .request({ method: "eth_chainId" });

Send transactions

You can send a transaction in EMG Pay using the eth_sendTransaction RPC method.

sendEthButton.addEventListener("click", () => {
    window.ethereum
        .request({
            method: "eth_sendTransaction",
            // The following sends an EIP-1559 transaction. Legacy transactions are also supported.
            params: [
                {
                    // The user's active address.
                    from: accounts[0],
                    // Required except during contract publications.
                    to: <recipient address>,
                    // Only required to send ether to the recipient from the initiating external account.
                    value: <value in wei to send>,
                    // Customizable by the user
                    gasLimit: '0x5028',
                    // Customizable by the user
                    maxPriorityFeePerGas: '0x3b9aca00',
                    // Customizable by the user
                    maxFeePerGas: '0x2540be400',
                },
            ],
        })
        .then((txHash) => console.log(txHash))
        .catch((error) => console.error(error));
});

Last updated