chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
28 lines • 1.32 kB
JavaScript
import { ethers, SigningKey } from 'ethers';
import { bytesToHex } from '../../../../InternalUtils/Utils';
import { EvmTransaction } from './EvmTransaction';
import { CurrencyWallet } from '../../CurrencyWallet';
export class EvmWallet extends CurrencyWallet {
constructor(utils, transports) {
super(utils, transports);
}
async getAddress() {
const publicKey = await (await this.transports.getPublicKeyProvider(this.utils.currencyInfo.id))();
return ethers.computeAddress(bytesToHex(publicKey.raw, true));
}
async getBalance() {
return this.utils.addressBalance(await this.getAddress());
}
async createTransfer(toAddress, amount) {
return this.prepareSmartContractTransaction(toAddress, amount, null);
}
async prepareSmartContractTransaction(smartContractAddress, amount, data) {
const privateKeyProvider = await this.transports.getPrivateKeyProvider(this.utils.currencyInfo.id);
return new EvmTransaction(this.utils, await this.getAddress(), smartContractAddress, amount, data, privateKeyProvider);
}
async signMessage(message) {
const signer = new ethers.Wallet(new SigningKey((await this.getPrivateKey()).raw));
return await signer.signMessage(message);
}
}
//# sourceMappingURL=EvmWallet.js.map