bc-web3js
Version:
A Typescript SDK for interacting with the ByteChain Blockchain.
42 lines (41 loc) • 1.26 kB
JavaScript
class Provider {
rpc_url;
constructor(rpc_url) {
this.rpc_url = rpc_url;
}
async check_nonce(addr) {
const res = await fetch(`${this.rpc_url}/nonce/${addr}`);
const n_nonce = (await res.json()).nonce;
return n_nonce;
}
async check_balance(addr) {
const res = await fetch(`${this.rpc_url}/balance/${addr}`);
const acc_bal = (await res.json()).balance;
return acc_bal;
}
async get_tx_pool() {
const res = await fetch(`${this.rpc_url}/tx/pool`);
const tx_pool = await res.json();
return tx_pool;
}
async get_block(block_num) {
const res = await fetch(`${this.rpc_url}/chain/${block_num}`);
const block = await res.json();
return block;
}
async get_chain() {
const res = await fetch(`${this.rpc_url}/chain`);
const chain = await res.json();
return chain;
}
async send_tx(tx) {
const res = await fetch(`${this.rpc_url}/tx/send`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(tx)
});
const tx_hash = (await res.json()).tx_id;
return tx_hash;
}
}
export default Provider;