UNPKG

bc-web3js

Version:

A Typescript SDK for interacting with the ByteChain Blockchain.

48 lines (47 loc) 1.46 kB
import Account from "./account.js"; import Provider from "./provider.js"; import Wallet from "./wallet.js"; class BCWeb3 { provider; wallet; constructor(node_url) { this.provider = new Provider(node_url); } async getBalance(address) { return await this.provider.check_balance(address); } async getNonce(address) { return await this.provider.check_nonce(address); } createAccount() { this.wallet = new Wallet(new Account(), this.provider); } loadAccount(privKey) { this.wallet = new Wallet(new Account(privKey), this.provider); } async getTxPool() { const transactionPool = await this.provider.get_tx_pool(); return [...transactionPool]; } async getBlock(block_id) { const block = await this.provider.get_block(block_id); return block; } async getChain() { const chain = await this.provider.get_chain(); return [...chain]; } async transfer(amount, recipient) { const transferResult = await this.wallet.send_byte(amount, recipient); return transferResult; } async deployContract(bytecode) { const deployResult = await this.wallet.deploy_contract(bytecode); return deployResult; } async callContract(contractAddr) { const callResult = await this.wallet.call_contract(contractAddr); return callResult; } } export default BCWeb3;