User Login

Retain the ownership of user transactions using Smart Contract Wallets

Biconomy uses Contract Wallet to relay the user’s transaction to your DApp smart contract so msg.sender in your smart contracts will be user’s contract wallet address, so user first needs to login to biconomy to use meta transactions. We just need users signature and public address to login.

Login API

When you use third party Wallets

Mexa exposes a login method to let your users login to biconomy to have their contract wallet created if user comes for the first time or just return existing contract wallet address for existing users.

This API internally trigger personal_sign RPC method to get user's signature which is handled by your web3 provider. Mostly this requires user to manually sign the login message.

biconomy.login(<public wallet address>, (error, response) => {
if(error) {
// Error while user login to biconomy
return;
}
​
if(response.transactionHash) {
// First time user. Contract wallet transaction pending. Wait for confirmation.
} else if(response.userContract) {
// Existing user login successful
}
});

When you implement your own Wallet

Mexa has accountLogin() method for the cases when your client code has access to User's private key, in those cases you do not want user to sign another message on a popup screen.

Method takes user's public wallet address and a message signature as argument. Message to be signed is fetched using the method getLoginMessageToSign()

let message = await biconomy.getLoginMessageToSign(<wallet public address>);
let signature = web3.eth.accounts.sign(message, 0x<private key>);
biconomy.accountLogin(address, signature.signature, (error, response)=>{
if(error) {
// Error while user login to biconomy
return;
}
​
if(response.transactionHash) {
// First time user. Contract wallet transaction pending.
// Wait for confirmation using Contract Wallet Confirmation method.
} else if(response.userContract) {
// Existing user login successful
}
});

Contract Wallet Confirmation

When user login for the first time, you’ll get the transaction hash for user’s contract wallet creation transaction. On transaction confirmation mexa will emit a confirmation event.

biconomy.on(biconomy.LOGIN_CONFIRMATION, (log) => {
// User's Contract Wallet creation successful
});

​