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

@devery/devery

v0.3.11

Published

Build decentralised apps on the Devery Protocol using Javascript.

Downloads

123

Readme

Devery.js

npm version Coverage Status Build Status

Javascript library for the Devery protocol.

You can check the full documentation with examples here ==> Devery.js documentation.

Installation:

The installation process is quite simple - you just need to install it using NPM or YARN.

npm install --save @devery/devery

That's it - now you can start using devery.js inside your app.

Importing:

You can use require or import like syntax to access devery classes

  1. require like syntax:
    const devery = require('@devery/devery');
    const DeveryRegistry = devery.DeveryRegistry;
    
    let deveryRegistryClient = new DeveryRegistry();

or alternatively you can use this.

  1. ES6 import syntax:
    import {DeveryRegistry} from '@devery/devery';
    
    let deveryRegistryClient = new DeveryRegistry();

Simple usage example

Important Read the permissioning session, to be aware of possible gotchas and pitfalls.

  1. Checking if a product has been marked.

      // first you need to get a {@link DeveryRegistry} instance
      let deveryRegistryClient = new DeveryRegistry();
    
      // check product by specified address
      deveryRegistryClient.check("0x627306090abaB3A6e1400e9345bC60c78a8BEf57").then(item => {
           console.log('product brand',item.brandAccount);
           // other stuff
      });
    
      // or with the async syntax
    
      async function foo() {
               let item = await deveryRegistryClient.check("0x627306090abaB3A6e1400e9345bC60c78a8BEf57")
               console.log('product brand',item.brandAccount);
      }

    usefull snippets

Create and mark a product for an existing brand

      import { DeveryRegistry, Utils } from '@devery/devery'
      async function markProduct (){
        let deveryRegistry = new DeveryRegistry();
        const address = Utils.getRandomAddress();

        let txn = await deveryRegistry.addProduct(product.productAccount, "product description", "product details", 2020, "Aukland")
        let provider = deveryRegistry.getProvider()
        await provider.provider.waitForTransaction(txn.hash)
        let hash = await deveryRegistry.addressHash(address)
        txn = await deveryRegistry.mark(address, hash)
        await provider.provider.waitForTransaction(txn.hash)
      }
      markProduct();

Mint token for an existing product


import { DeveryERC721, Utils } from '@devery/devery'

async function claim (){
        let deveryErc721 = new DeveryERC721();
        
        let txn = await deveryErc721.claimProduct(product.address, quantity)
        let provider = deveryErc721.getProvider()
        await provider.provider.waitForTransaction(txn.hash)
        
      }

      claim();

Access to the ethereum network

Devery.js will try to automatically get the web3 object instance presented in your context(page, app etc). If this is not possible then it will fallback to a read only provider pointing to the main network. As the fallback does not contain a signer you will not be able to perform write operations.

Permissioning

web3 permissioning

Metamask requires you to give permission to your app by default. So it's very important to call web3.currentProvider.enable() to open Metamask permission window. It's a good idea to safeguard your code for the case when web3 is not presented. One example of how to request these permissions safely would be:

// init metamask
try {
  if (web3 && web3.currentProvider && web3.currentProvider.isMetaMask) {
    // TODO: move this to deveryjs
    web3.currentProvider.enable();
  }
} 
catch(e) {
    // Handle exceptions here
}

If you don't do this you will not be able to interact with the contracts using Metamask.

Fee charge permissions

Some operations may charge a fee from the message sender. Example of these transactions is marking a product and claiming a token for a marked item. The contracts that charge these fees need your permission, you can pre approve these transfers by calling the approve EveToken.

Here's a full example on how to check the current allowance and try to increase the approval if it's bellow a certain number

export async function checkAndUpdateAllowance (address, minAllowance , total) {
  try {
    // creates a new eve token instance
    let eveTokenClient = new EveToken();
    // get the current ethereum network connection provider
    let provider = eveTokenClient.getProvider();
    // check the current allowance for the requested contract
    let currentAllowance = await eveToken.allowance(web3.eth.accounts[0], address);
    // we need to do the division by 10e17 because devery token uses the base 18
    if(parseFloat(currentAllowance.toString()) / 10e17 < minAllowance) {
        // here in the approve function we need to add the 17 0s for the same reason
        let txn = await eveTokenClient.approve(address, total + '000000000000000000');
        await provider.provider.waitForTransaction(txn.hash);
    }
   
  } catch (e) {
      // Add your exception handling here
  }
}

// checks and approves the allowance for the deveryRegistry contract
checkAndUpdateAllowance('0x0364a98148b7031451e79b93449b20090d79702a',40,100);

// checks and approves the allowance for the deveryErc721 contract
checkAndUpdateAllowance('0x032ef0359eb068d3dddd6e91021c02f397afce5a',40,100);

This example would check and approve the allowance for both transactions (marking and claiming tokens) in the live network, you can always improve and change the code to fit your needs.

Main Classes documentation.

  1. DeveryRegistry
  2. DeveryERC721
  3. EveToken