# metatx-handler

> Utilities library for meta transactions, descended from metatx-server

Latest version **1.0.13** (published 2020-03-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install metatx-handler
pnpm add metatx-handler
yarn add metatx-handler
bun add metatx-handler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2020-03-03 |
| First published | 2020-02-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 43.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | ana0, shkfnly |
| Maintainers | ana0 |
| Keywords | blockchain, ethereum, metatx |

## Links

- npm: https://www.npmjs.com/package/metatx-handler
- Repository: https://github.com/CirclesUBI/metatx-server
- Homepage: https://github.com/CirclesUBI/metatx-server#readme
- Issues: https://github.com/CirclesUBI/metatx-server/issues
- npm.io page: https://npm.io/package/metatx-handler

## Dependencies (3)

- [web3](https://npm.io/package/web3.md) ^1.0.0-beta.48
- [eth-signer](https://npm.io/package/eth-signer.md) ^0.3.4
- [ethereumjs-tx](https://npm.io/package/ethereumjs-tx.md) ^1.3.7

## Recent versions

- 1.0.13 (latest) — 2020-03-03
- 1.0.12 — 2020-03-03
- 1.0.10 — 2020-02-28
- 1.0.9 — 2020-02-24

## README

# metatx-server

### This package is for serverside processing of ethereum meta transactions.  It is the server side component of [metatx-client](https://www.npmjs.com/package/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 })
  }
```

---
_Source: https://npm.io/package/metatx-handler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
