const { fromBech32 } = require('@harmony-js/crypto');
export class MathWallet {
constructor(network, client) {
console.log(network, client);
this.isMathWallet = false;
this.mathwallet.getAccount().then((account) => {
this.sessionType = `mathwallet`;
this.address = account.address;
this.isAuthorized = true;
return Promise.resolve();
this.isMathWallet = window.harmony && window.harmony.isMathWallet;
this.mathwallet = window.harmony;
async signTransaction(txn) {
console.log(this.isMathWallet);
if (this.sessionType === 'mathwallet' && this.isMathWallet) {
console.log(this.mathwallet);
return this.mathwallet.signTransaction(txn);
attachToContract(contract) {
contract.wallet.createAccount();
if (contract.wallet.defaultSigner === '') {
contract.wallet.defaultSigner = this.address;
contract.wallet.signTransaction = async (tx) => {
const signTx = await this.signTransaction(tx);
if (err.type === 'locked') {
'Your MathWallet is locked! Please unlock it and try again!'
} else if (err.type === 'networkError') {
const signTx = await this.signTransaction(tx);
return Promise.reject(error);
'An error occurred - please check that you have MathWallet installed and that it is properly configured!'