0.1.14 • Published 1 year ago

evm-ext v0.1.14

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Evm Ext

TODO

  • modules
  • tools adapters
  • multicall contracts
  • rewrite README.md
  • tests

PROJECT IN ALPHA

Example of Usage

What is it for ?

evm-ext - tool for interacting with EVM-compliant blockchains and blockchain contracts

Typescript Disclamer

This package make Blockchain integration stongly typed

Getting started

# install package
yarn add evm-ext@latest
# init config file
npx evm-ext init -p ./src/evm.config.ts

Config file

import { defineEvmConfig, modules, utils } from 'evm-ext'
import { wallets } from 'evm-ext-wallets'

import type { Token, Staking } from './contracts/typechain'
import contractsJSON from './contracts/contracts.json'

export const useEvm = defineEvmConfig({
  /// contratcts' source file with chains, addresses and ABIs
  contractsJSON,
  /// target chainIds for your DApp
  chainIds: ['97'],
  /// default chainId for your DApp (chain which `evm-ext` will connect your users)
  DEFAULT_CHAINID: '97',
  /// rpc function for provider
  rpc: utils.rpc.universalRpc(),
  /// contracts definition
  contracts: {
    /// contracts shared on all chains in `chainIds`
    shared: {
      /// name of contract
      staking: {
        /// name of contract in `contractsJSON`
        name: 'Staking',
        /// type of contract generated by `typechain` package (optional)
        type: modules.contracts.contractType<Staking>(),
      },
    },
    /// contracts on specific chains
    on: {
      '97': {
        anyToken: {
          /// name of contract in `contractsJSON`
          name: 'Token',
          /// type of contract generated by `typechain` package (optional)
          type: modules.contracts.contractType<Token>(),
          /// you can user this contract with any address and any chain (optional)
          withAddress: true,
        },
      },
    },
  },
  /// supported wallets for app
  wallets,
  /// objects which will be triggered on specific lifecycles
  stores: {},
  /// adapter for connection `evm-ext` to different frameworks and environments
  adapter,
})

ContractsJSON

It is source file for your contracts (generated by hardhat-deploy plugin for hardhat)

export type ContractsJSONStruct = {
  [ChainId in string]: {
    name: string
    chainId: ChainId
    contracts: Record<
      string,
      {
        address: string
        abi: any
      }
    >
  }[]
}

Example

{
    "97": {
        [
            {
                "name": "bsc_testnet",
                "chainId": "97",
                "contracts": {
                    "Token": {
                        "address": "0xSomeAddress",
                        "abi": [
                            ...
                        ]
                    }
                }
            }
        ]
    },
    ...
}

Wallet connection

You can use useEvm function to connect to different wallets in browser

  • Metamask
  • WalletConnect
  • CoinBase

And more in future

Exmaple of connection

import { useEvm } from './emv.config.ts'

const { useWallet } = useEvm()
const { connect } = useWallet()

connect('metamask')
// connect('walletconnect')
// connect('coinbase')

All information about user connection will be saved in state of package For example for vue3 state is pinia stores

Contract Interaction

You can interact with contracts by using useContracts, everything strongly typed

import { useEvm, safeRead } from './emv.config.ts'
const { useContracts } = useEvm()

async function main() {
  const { token } = useContracts()
  const symbol = await safeRead(token.symbol(), 'TKN')
}

Safe calls

evm-ext has three function for safe call to contracts

  • safe - make safe async call and returns [response, error]
  • safeRead - make safe async read call to contract with default value, if call is success returns response otherwise defaultValue
  • safeWrite - make safe async write call to contract with auto tx.wait() and returns [tx, rpt] - Transaction object and Reciept object from ethers

Lifecycles

evm-ext has lifecycles

  • init - lifecycle which runs on start of app
  • login - lifecycle which runs on user connection
  • logout - lifecycle which runs on user disconnection
  • final - lifeycycle which runs every time on any lifecycles
0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.0.17-a4

1 year ago

0.0.17-a3

1 year ago

0.0.17-a2

1 year ago

0.0.17-a1

1 year ago

0.0.17-ab

1 year ago

0.0.17-af

1 year ago

0.0.17-a

1 year ago

0.0.16-a

1 year ago

0.0.15-a

1 year ago

0.0.14-a

1 year ago

0.0.13-a

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago