npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chainbrary/token-bridge

v17.0.1

Published

The @chainbrary/token-bridge library provides an Angular service, Erc20Service, developed by the Chainbrary's team for easy interaction with the Ethereum ERC-20 token standard. It provides a set of methods that allow you to perform various token-related o

Downloads

106

Readme

@chainbrary/token-bridge

The @chainbrary/token-bridge library provides an Angular service, Erc20Service, developed by the Chainbrary's team for easy interaction with the Ethereum ERC-20 token standard. It provides a set of methods that allow you to perform various token-related operations, such as getting the token balance of an address, checking the token allowance of an address, increasing or decreasing token allowance, transferring tokens between addresses, and approving an address to spend tokens on your behalf.

This service relies on the Web3.js library to communicate with the Ethereum blockchain.

Installation

To use the Erc20Service, you need to install the required dependencies:

npm install web3 @chainbrary/token-bridge

Make sure you also have the Angular service imported into your project.

Usage First, import the service and its associated interfaces in your component or service:

import { Erc20Service } from '@chainbrary/token-bridge';
import { IBalancePayload, IAllowancePayload, IEditAllowancePayload, ITransferPayload } from '@chainbrary/token-bridge';

Then, inject the service in the constructor of your component or service:

constructor(private erc20Service: Erc20Service) {}

Methods

The following methods are available in the Erc20Service class:

getBalance

getBalance(payload: IBalancePayload): Promise<number> to get the token balance of the given address.

Example:

const payload: IBalancePayload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  owner: '0x0987654321098765432109876543210987654321'
};
const balance = await this.erc20Service.getBalance(payload);
console.log(`Balance: ${balance}`);

getAllowance

getAllowance(payload: IAllowancePayload): Promise<number> to get the token allowance of the given address.

Example:

const payload: IAllowancePayload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  owner: '0x0987654321098765432109876543210987654321',
  spender: '0x5678901234567890123456789012345678901234'
};
const allowance = await this.erc20Service.getAllowance(payload);
console.log(`Allowance: ${allowance}`);

increaseAllowance

increaseAllowance(payload: IEditAllowancePayload): Promise<boolean> to increase the token allowance of the given address.

Example:

const payload: IEditAllowancePayload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  owner: '0x0987654321098765432109876543210987654321',
  spender: '0x5678901234567890123456789012345678901234',
  amount: 100
};
const result = await this.erc20Service.increaseAllowance(payload);
console.log(`Transaction Success: ${result}`);

decreaseAllowance

decreaseAllowance(payload: IEditAllowancePayload): Promise<boolean> to decrease the token allowance of the given address.

Example:

const payload: IEditAllowancePayload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  owner: '0x0987654321098765432109876543210987654321',
  spender: '0x5678901234567890123456789012345678901234',
  amount: 50
};
const result = await this.erc20Service.decreaseAllowance(payload);
console.log(`Transaction Success: ${result}`);

transfer

transfer(payload: ITransferPayload): Promise<boolean> to transfer tokens between addresses.

Example:

const payload: ITransferPayload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  amount: 100,
  from: '0x0987654321098765432109876543210987654321',
  to: '0x5678901234567890123456789012345678901234'
};
const result = await this.erc20Service.transfer(payload);
console.log(`Transaction Success: ${result}`);

approve

approve(payload: IEditAllowancePayload): Promise<boolean> to approve an address to spend tokens on your behalf.

Example:

const payload = {
  tokenAddress: '0x1234567890123456789012345678901234567890',
  chainId: '1',
  owner: '0x0987654321098765432109876543210987654321',
  spender: '0x5678901234567890123456789012345678901234',
  amount: 200
};
const result = await this.erc20Service.approve(payload);
console.log(`Transaction Success: ${result}`);

Credits

This library was developed by the Chainbrary's team.

Note: Make sure you have an Ethereum provider (such as MetaMask) installed and configured properly before using the service.

Please be aware that interacting with blockchain networks might involve transaction fees, and the operations could fail due to various reasons, such as insufficient funds, rejected transactions, etc. Always handle errors properly and inform users about possible outcomes.

Feedback and Improvements

We value your feedback and are committed to continuously improving the Chainbrary library. Your suggestions, comments, and ideas will help shape the future of this project. Please don't hesitate to share your thoughts with us through the contact channels listed above. We will strive to incorporate your feedback into future updates to enhance the library for all users.

Contact Us

For any questions, feedback, or concerns, please feel free to contact us through the following channels:

License

The @chainbrary/token-bridge package is released under the MIT License.

Let me know if you need any additional information or if you have any questions. I'm happy to help!