0.1.0-beta.1 • Published 2 years ago

@web3-systems/evm-morphism v0.1.0-beta.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

☯️ EVM Morphism

CI TS GPLv3 license npm

The @web3-systems/evm-morphism node module handles EVM data transformations using morphism schemas - converting object structs via mappings.

💾 Installation

Install NPM package:

npm install @web3-systems/evm-morphism
yarn add @web3-systems/evm-morphism

Clone from Github:

git clone https://github.com/web3-systems/evm-morphism

🏎️ Quickstart

Etherscan provides a simple method for accessing an Account transaction history. The return object doesn't exactly match the base EVM transaction type. Thus, we run the Account.transaction entity through an EVM transaction adapter to normalize set entites before running compute actions.

import EVMMorphism, { schemas } from '@web3-systems/evm-morphism'; 

const schemaLoad = { txTransform: schemas.evmTransactionFromEtherscanTransaction }
const evmMorphism = new EVMMorphism(schemaLoad);

const etherscanAccountTxlistItem = {
    blockNumber: '207947',
    timeStamp: '1441800674',
    hash: '0xf7dbf98bcebd7b803917e00e7e3292843a4b7bf66016638811cea4705a32d73e',
    nonce: '23',
    blockHash: '0x0e37d0025471662915d7a15ade9a13e75cbbcc239bdbc4ea46a01d9b268a7e60',
    transactionIndex: '0',
    from: '0x5ed8cee6b63b1c6afce3ad7c92f4fd7e1b8fad9f',
    to: '0xab5801a7d398351b8be11c439e05c5b3259aec9b',
    value: '0',
    gas: '90000',
    gasPrice: '50000000000',
    isError: '0',
    txreceipt_status: '',
    input: '0x123123123123',
    contractAddress: '',
    cumulativeGasUsed: '21408',
    gasUsed: '21408',
    confirmations: '13847862'
}
const morphed = evmMorphism.morph('txTransform', etherscanAccountTxlistItem)
/*
{
    hash: '0xf7dbf98bcebd7b803917e00e7e3292843a4b7bf66016638811cea4705a32d73e',
    from: '0x5ed8cee6b63b1c6afce3ad7c92f4fd7e1b8fad9f',
    to: '0xab5801a7d398351b8be11c439e05c5b3259aec9b',
    creates:'',
    nonce: '23',
    blockNumber: '207947',
    blockHash: '0x0e37d0025471662915d7a15ade9a13e75cbbcc239bdbc4ea46a01d9b268a7e60',
    timeStamp: '1441800674',
    value: '0',
    gasLimit: '90000',
    gasPrice: '50000000000',
    chainId: "1",
    data: '0x123123123123',
    type: "0",
    transactionIndex: '0',
    r: '',
    s: '',
    v: '',
    accessList: null
}
*/

💻 Developer Experience

The package is setup using the TSDX zero-config CLI which includes:

  • Typescript
  • Rollup
  • Jest
  • Prettier
  • ESLint