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

@dattabot-blockchain/geneth-tx

v1.1.9

Published

Javascript SDK to interact with smart contract that implements EIP-137

Downloads

139

Readme

Javascript SDK to interact with smart contract that implements EIP-137

How To

1. Install Package

npm install generalized-sdk

2. Set Environment Variables(optional):

You need to set environment variables: ENS_ADDRESS, and RPC.

For example:

export ENS_ADDRESS=my_ens_address
export RPC=my_rpc

Default Environment Variables:

This is the default setting if you do not set it

ENS_ADDRESS=0x6833934d94fb4bebb9a780c5af3848a3de0c1f0e
RPC=https://testnet.haratoken.app

Functions

Constructor

You can set which web3 you want to use when initiating new instance.

let SDK = new GeneralizeSDK(my_ens_address, my_web3);

Parameters

  1. my_ens_address(optional) : Ens address
  2. my_web3(optional) : Your web3

setRPC

Set RPC to interact with

SDK.setRPC(_yourRPC);

Will return a new Web3 instance if succeded and boolean 'false' if failed. Currently listed chain ID for transaction are :

  1. mainnet
  2. morden
  3. ropsten
  4. rinkeby
  5. goerli
  6. kovan
  7. haratoken

You can add your own customize chain ID here at SDK/chainID.json

Fetch

Get transaction hash

SDK.fetch(obj);

Parameters

  1. Object : Object you have to define to interact with SDK
    • uri: ENS name
    • fn: which function you want call/send
    • addr: address used to call the contract (resolved using current web3 if not defined)
    • callback : an object that has following functions:
      • sign(tx): function to sign transaction. Have to return raw of the signedTransaction
      • getAddress(): function to get sender of the transaction. Have to return the sender address
    • params: array of parameters

Returns

You will get an Object with following attribute:

  • txHash : Transaction hash if you send transaction to blockchain

    or

  • result : Data from smart contract if you pass call function

Example

let objSend =  {
    uri : 'attesttest.hara.ethnet',
    fn : 'attest',
    callback: {
        sign: async (tx)=>{
            let pk = web3.utils.sha3(seed +  process.env['TOKEN_SALT']);
            let acc = web3.eth.accounts.privateKeyToAccount(pk);
            tx.fromAddress = acc.address;
            let signedTx = await acc.signTransaction(tx);
            return signedTx.rawTransaction;
        },
        getAddress: async ()=>{
            let pk = web3.utils.sha3(seed + process.env['TOKEN_SALT']);
            return web3.eth.accounts.privateKeyToAccount(pk).address;
        }
    },
    params : [
        initVersion,
        initItemAddress,
        initTopic,
        initValue,
        initExpiredTime
    ]
};

Object for call

let objCall =  {
    uri : 'attesttest.hara.ethnet',
    fn : 'getValue',
    callback: {
        sign: async (tx)=>{
            let pk = web3.utils.sha3(seed +  process.env['TOKEN_SALT']);
            let acc = web3.eth.accounts.privateKeyToAccount(pk);
            tx.fromAddress = acc.address;
            let signedTx = await acc.signTransaction(tx);
            return signedTx.rawTransaction;
        },
        getAddress: async ()=>{
            let pk = web3.utils.sha3(seed + process.env['TOKEN_SALT']);
            return web3.eth.accounts.privateKeyToAccount(pk).address;
        }
    },
    params : [
        initVersion,
        initItemAddress,
        initTopic,
        attestorAddress
    ]
};

Get Transaction Hash

Remember you can still get transaction hash even though the transaction has not mined yet.

There two ways to get transaction hash from send transaction object:

.then

SDK.fetch(obj).then(result=>{
    console.log(result.txHash)
}).catch(err=>{
    ...
});

async/await

try{
    let result = await SDK.fetch(obj);
    txHash = result.txHash;
}catch(err){
    ...
}

getTransactionReceipt

You need to wait several seconds for transaction to be mined/confirmed

SDK.getTransactionReceipt(txHash);

Parameters

  • txHash : Transaction hash

Returns

  • receipt : Full receipt of the transaction hash

getPastEvents(Not Tested Yet)

To get past events that are emitted from a smart contract from block 0 to latest

SDK.getPastEvents(uri, eventName, filter);

Parameters

  • uri : ENS or HNS name
  • eventName : Event name
  • filter : an Object that needs to follow these rules:
    1. The key in the object is the event variable name followed by its value
    2. The value of the element is in array form

Returns

Promise returns

  • Array : an array consists of event objects

Example

events = await SDK.getPastEvents(
    'attest.hara.ethnet',//uri
    'AttestLog', //eventName
    {itemAddress:[0xfaC4316f68389F1b1ec40Cb39113Ea8F8BFb8DdD], //filter
     version:['0x000000c.....']} //the each value is in an array
    );

Testing

You need to define MNEMONIC in environment variable

Rename test.example.sh to test.sh

test.sh will contain:

    export ENS_ADDRESS=0xmy_ens_address..
    export RPC=my_rpc
    export MNEMONIC=my_mnemonic_words
    npm run test

then execute test.sh in terminal

. test.sh