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

metatx-server

v1.0.12

Published

Meta Tx for the backend server

Downloads

10

Readme

metatx-server

This package is for serverside processing of ethereum meta transactions. It is the server side component of metatx-client, but it can also be used on it's own.

Exposes a class MetaTxHandler that should be instantiated like this:

const metaTxHandler = new MetaTxHandler(
  relayerPrivKey,     // required arg. The private key that will relay transactions
  provider,           // required arg. Your web3 provider
  txRelayAddress,     // required arg. The address of your relayer contract
  txRelayABI,         // required arg. The abi of your relayer contract
  logger              // optional arg. Your logger, if you use one. Should have levels info and error
)

Methods:

getRelayerAddress => returns the given relayer address

getRelayNonce (address) => returns the nonce held in the relayer contract of the given address. A relayer nonce is required to prevent replay attacks.

initSimpleSigner => generates an eth-signer signer from the relayer private key given in the contructor

getSenderKeyPair (senderPrivKey) => generates a keypair from any given private key

initTxRelaySigner (senderPrivKey, _whitelist) => generates an eth-signer signer for the given sender private key. senderPrivKey is required, whitelist is optional.

estimateGas (tx, txSender) => estimates gas cost of a transaction, formatted in rlp.

isMetaSignatureValid (metaSignedTx, metaNonce) => verified that a meta signature is valid. metaSignedTx is a signed meta transaction and metaNonce is the nonce of the sender as of the relayer contract.

signMetaTx (txParams, senderPrivKey, relayNonce, whitelist) => prepares a signed meta transaction. txParams is an object that can be constructed like this:

const tx = {
  from: address,
  to: contractAddress,
  value: 0,
  data: Contract.methods.methodName(methodArgs).encodeABI()
};

senderPrivKey is the private key of the from address is txParams. relayNonce is optional, and will default to the relayer address set in the constructor. whitelist is also optional.

signRelayerTx (txHex) => Signs a meta transaction for forwarding to the relayer contract. txHex should be the signed meta tx in rlp encoding. Also estimates the gas price needed to execute the transaction.

sendRawTransaction (signedRawTx) => signes and sends a raw transaction to provider

handle (req) => Fully handles a request to the server to process a meta transaction. Can be used like this:

const relay = async (req, res) => {
  try {
    const result = await MetaTxHandler.handle(req)
    return res.status(200).json({ result })
  } catch (err) {
    return res.status(error.code).json({ error: error.message })
  }