ethwrapper
Version:
♻️ Utility class to wrap/unwrap ETH on compatible networks
39 lines (38 loc) • 1.62 kB
TypeScript
import { EthWrapperOptions, EthWrapperWrapOptions } from '../types/index';
/**
* Utility class used to wrap and unwrap ETH on any network that used ETH as a native currency and has an ERC20 WETH
* contract
*/
export default class EthWrapper {
private wallet;
private wethContractAddress;
private provider;
private signer;
/**
* Creates an EthWrapper instance
*
* @param {EthWrapperOptions} options
* @param {String} options.rpcEndpointUrl The url of the JSON RPC of the network
* @param {String} options.wethContractAddress The address of the WETH contract for this network
* @param {EthWrapperOptionsWallet} options.wallet
* @param {String} options.wallet.address The address of the wallet used to wrap/unwrap
* @param {String} options.wallet.privateKey The private key of the wallet used to wrap/unwrap
*/
constructor({ rpcEndpointUrl, wethContractAddress, wallet }: EthWrapperOptions);
/**
* Wraps native ETH to ERC20 WETH
*
* @param {EthWrapperWrapOptions} options
* @param {Number} options.amount The amount of ETH to wrap (in ETH readable format)
* @returns {Promise<string>} Hash of the wrap transaction
*/
wrap({ amount }: EthWrapperWrapOptions): Promise<string>;
/**
* Unwraps ERC20 WETH to native ETH
*
* @param {EthWrapperWrapOptions} options
* @param {Number} options.amount The amount of WETH to unwrap (in WETH units - readable format)
* @returns {Promise<string>} Hash of the unwrap transaction
*/
unwrap({ amount }: EthWrapperWrapOptions): Promise<string>;
}