Skip to main content

usage-guide

Note

Currently developing documentation, contributions are always welcome

Import service into your component

import { Web3Service } from "ng-blockchainx";

Create an object for web3Service using constructor

  constructor(web3Service: Web3Service){ }

Connect

Connect to web3Service service to instantiate the dependencies

Refer connectParams, connectResponse

const param: connectParams;

this.web3Service.connect(param)
.then((connection: connectResponse) => {
// Do your logic here
})
.catch((error: connectResponse) => {
// handle error here
})

Create contract instance

this.web3Service.getContract(ABI: any, contractAddress: string)
.then((contract: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})

Encode ABI

this.web3Service.encodeABI(functionName: string, ...params: any)
.then((abi: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})

Send transaction

Refer SendTransactionParam

this.web3Service.sendTransaction(data: SendTransactionParam)
.then((transaction: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})

Get token balance

this.web3Service.getTokenBalance(address: string)
.then((balance: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})

Get allowance balance

this.web3Service.getAllowance(owner: string, spender: string)
.then((allowance: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})

Approve

this.web3Service.approve(data: ApproveParam)
.then((transaction: any) => {
// Do your logic here
})
.catch((error: any) => {
// handle error here
})