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

casper-erc20-js-client-test

v0.0.2

Published

Casper ERC20(CEP18) JavaScript Client

Downloads

2

Readme

casper-erc20-js-client

This JavaScript client gives you an easy way to install and interact with the Casper ERC-20 contract.

Installation

Run this command to install the client:

npm i casper-erc20-js-client

Usage example

  • Create an instance of the ERC-20 client:

    const erc20 = new ERC20Client(
      client, // CasperClient
      'hash-8e7b7820566b1aa9349f168245bedf003a305282baa8c53a5fa1e0efdfa04b8e', // Contract Hash optional
      'hash-eb13cd75118f1eae57ad7be0d707b069b70e5362fe68b045fa4924195735e51b' // Contract Package Hash optional
    );
  • Install the contract:

    const deploy = await erc20.installERC20(
      wasm, // Contract wasm
      {
        name: tokenName,
        symbol: tokenSymbol,
        decimals: tokenDecimals,
        totalSupply: totalSupply
      },
      60_000_000_000, // Payment Amount
      ownerPublicKey,
      CHAIN_NAME,
      [owner]
    );
    
    await client.putDeploy(deploy);
    
    const result = await client.nodeClient.waitForDeploy(deploy);
  • Set the contract hash (a unique identifier for the network):

    erc20.setContractHash(
      'hash-c2402c3d88b13f14390ff46fde9c06b8590c9e45a9802f7fb8a2674ff9c1e5b1'
    );
  • You can retrieve token infomation by calling these methods:

    const name = await erc20.name();
    
    const symbol = await erc20.symbol();
    
    const totalSupply = await erc20.totalSupply();
    
    const decimals = await erc20.decimals();
  • Transfers

    • Transfer some tokens from the direct caller to a recipient:

      const deploy = erc20.transfer(
        { recipient: recipientPublicKey, amount: 50_000_000_000 },
        5_000_000_000, // Payment amount
        ownerPublicKey,
        CHAIN_NAME,
        [ownerAsymmetricKey] // Optional
      );
    • Transfer from an account owner to a recipient given that the direct caller has been previously approved to spend the specified amount on behalf of the owner:

      const deploy = erc20.transferFrom(
        {
          owner: ownerPublicKey,
          recipient: recipientPublicKey,
          amount: transferAmount
        },
        5_000_000_000,
        approvedPublicKey,
        CHAIN_NAME,
        [approvedAsymmetricKey]
      );
  • Balances

    Request the balance of an account with balanceOf:

    const balance = await erc20.balanceOf(publicKey);
  • Approvals

    Allow a spender to transfer up to a number of the direct caller’s tokens:

    const deploy = erc20.approve(
      {
        spender: spenderPublicKey,
        amount: approveAmount
      },
      5_000_000_000,
      ownerPublicKey,
      CHAIN_NAME,
      [ownerAsymmetricKey]
    );
  • Allowance

    Return the number of owner’s tokens allowed to be spent by spender:

    const allowance = await erc20.allowances(
      ownersPublicKey,
      spenderPublicKey
    );

More examples

You can find all the available examples in the E2E test script.

Test

  • Clone this repo
git clone https://github.com/casper-ecosystem/erc20.git
  • Go to client directory
cd client
  • Intall modules using
npm install
  • You can test the script by running the local network. After running the local network run the test by
npm test