📜  Biliothek - Javascript (1)

📅  最后修改于: 2023-12-03 14:39:31.377000             🧑  作者: Mango

Biliothek - Javascript

Biliothek is a Javascript library for building Web3 dApps using the Ethereum blockchain. It provides a set of methods and classes that make it easier to interact with the Ethereum network, read and write smart contract data, and manage user accounts.

Usage

To use Biliothek in your project, simply include it in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/biliothek/dist/biliothek.min.js"></script>

Once included, you can start using Biliothek in your Javascript code:

const biliothek = new Biliothek();

// Set the provider for the Ethereum network
biliothek.setProvider("https://mainnet.infura.io/v3/your-project-id");

// Get the accounts of the connected user
const accounts = await biliothek.getAccounts();
console.log(accounts);

// Read data from a smart contract
const contractAddress = "0x1234567890123456789012345678901234567890";
const contractAbi = []; // ABI of the smart contract
const contract = biliothek.getContract(contractAbi, contractAddress);
const result = await contract.methods.getData().call();
console.log(result);

// Write data to a smart contract
const data = "Hello, world!";
const transaction = await contract.methods.setData(data).send({from: accounts[0]});
console.log(transaction);
Features

Biliothek provides the following features:

Web3

Biliothek provides an instance of the Web3 object for interacting with the Ethereum network.

const web3 = biliothek.getWeb3();
Accounts

Biliothek provides methods for getting the accounts of the connected user.

const accounts = await biliothek.getAccounts();
Contract

Biliothek provides a Contract class for interacting with smart contracts.

const contractAbi = []; // ABI of the smart contract
const contractAddress = "0x1234567890123456789012345678901234567890";

// Get an instance of the Contract class
const contract = biliothek.getContract(contractAbi, contractAddress);

// Call a method on the smart contract
const result = await contract.methods.getData().call();

// Send a transaction to the smart contract
const transaction = await contract.methods.setData("Hello, world!").send({from: accounts[0]});
Signatures

Biliothek provides methods for signing Ethereum transactions and messages.

const data = "Hello, world!";

// Sign a message
const signature = await biliothek.signMessage(data);

// Send a signed transaction
const transaction = await biliothek.sendSignedTransaction(rawTransaction);
Crypto

Biliothek provides methods for generating Ethereum addresses and private keys.

// Generate a new Ethereum address and private key
const {address, privateKey} = biliothek.generateAccount();