hypesdk
Version:
A powerful SDK for interacting with the Hype blockchain, featuring advanced routing and token swap capabilities
39 lines (38 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWallet = createWallet;
exports.getTokenInfo = getTokenInfo;
const ethers_1 = require("ethers");
const constants_1 = require("../constants");
/**
* Creates a new wallet
* @returns {object} Object containing the wallet's address and private key
*/
function createWallet() {
const wallet = ethers_1.ethers.Wallet.createRandom();
return {
address: wallet.address,
privateKey: wallet.privateKey,
};
}
/**
* Get token information and balance for an address
* @param provider Ethers provider instance
* @param tokenAddress The token contract address
* @param walletAddress The wallet address to check balance for
* @returns Token information including decimals, balance, and symbol
*/
async function getTokenInfo(provider, tokenAddress, walletAddress) {
const tokenContract = new ethers_1.ethers.Contract(tokenAddress, constants_1.ERC20_ABI, provider);
const [decimals, rawBalance, symbol] = await Promise.all([
tokenContract.decimals(),
tokenContract.balanceOf(walletAddress),
tokenContract.symbol(),
]);
return {
decimals,
rawBalance,
symbol,
formattedBalance: ethers_1.ethers.formatUnits(rawBalance, decimals),
};
}