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

@telosnetwork/telosevm-js

v0.3.1

Published

Telos EVM JS SDK

Downloads

155

Readme

Telos EVM JS SDK

Installation

Requires nodejs and npm installed

npm install @telosnetwork/telosevm-js

How to setup EVM and deploy ERC-20 Token on EOSIO in 5 minutes

const { TelosEvmApi } = require('telosevm-js')
const fetch = require('node-fetch') // only for node
const evmContractAccount = 'evmcontract2'
const evmNormalAccount = 'evmaccount11'
const SYSTEM_SYMBOL = 'TLOS'

const api = new TelosEvmApi({
  // Ensure the API has console printing enabled
  endpoint: 'https://api.telos-test.eostribe.io',

  // Must match the chain ID the contract is compiled with (1 by default)
  chainId: 41,

  // Enter your own private keys if you wish to sign transaction (examples provided)
  ethPrivateKeys: [
    // Public Key: 0xf79b834a37f3143f4a73fc3934edac67fd3a01cd
    '0x8dd3ec4846cecac347a830b758bf7e438c4d9b36a396b189610c90b57a70163d',
  ],

  // Enter Telos account that EVM is at / will be deployed to
  telosContract: evmContractAccount,

  fetch: fetch,
  // Enter your own private keys (examples provided)
  telosPrivateKeys: [
    // evmcontract2 (EOS7DJzWuEr1Zu36ZX8GXwGsvNNqdGqx8QRs7KPkqCMTxG6MBT1Eu)
    '5JACk8gJ98x3AkypbicNQviXzkqAM2wbbE3FtA79icT2Ks4bWws',
    // evmaccount11 (EOS8Z9y2b1GfAkFUQxBTsiu9DJSLebVoU8cpwLAfXcgWDRWg9aM2Q)
    '5JhwbcHTVk16Pv7fCgitNSHgwGwjAPEgEJbiaCcXaza1PKrbCns'
  ]
})

// Import contract compiled with solc (check telosevm-js/src/eth-contracts/compile.ts to compile your own)
// We provide compiled ERC20 and ERC721 contracts
// NOTE: this may not be included in the NPM, possibly download from github
const compiledErc20AndErc721 = require('@telosnetwork/telosevm-js/dist/eth-contracts/compiled.json')

// Load ETH contracts with abi and bytecode, plus the TX sending Telos account
api.loadContractFromAbi({
  account: evmNormalAccount, // Example Telos account
  abi: compiledErc20AndErc721.contracts.ERC20.Token.abi,
  bytecodeObject: compiledErc20AndErc721.contracts.ERC20.Token.evm.bytecode.object
})

async function main () {
  // For development (if TESTING is enabled in contract), clears all data in contract
  await api.telos.clearAll()

  // Creates new address based on RLP(eosaccount, arbitrarydata)
  await api.telos.create({ account: evmNormalAccount, data: 'test' })

  // Transfer Telos to contract to deposit to address
  await api.telos.deposit({ from: evmNormalAccount, quantity: `0.0002 ${SYSTEM_SYMBOL}` })

  // Get all data for new address (address, account, nonce, balance, code)
  const sender = await api.telos.getEthAccountByTelosAccount(evmNormalAccount)
  console.log(`${sender.address} (${evmNormalAccount}) Balance:`, sender.balance) // 0.0001 TLOS
  console.log(`${sender.address} (${evmNormalAccount}) Nonce:`, sender.nonce) // 0

  // Deploy ERC20 contract (Name, Symbol, Decimals, Total Supply)
  // The returned response "eth" is the EVM transaction receipt, and "tlos" is the Telos transaction receipt
  const { eth, tlos } = await api.eth.deploy('FIRE Token', 'FIRE', 4, 1000000, { sender: sender.address })

  // Set the created address as the EVM contract to interact with
  api.setEthereumContract(eth.createdAddress)

  // Query ERC20 balance using "view" function calls
  console.log(`${sender.address} FIRE Balance: `, +(await api.eth.balanceOf(sender.address)).toString(10)) // 1,000,000

  // New receiver address to send tokens to
  const receiver = '0xf79b834a37f3143f4a73fc3934edac67fd3a01cd'

  // Transfer system tokens to address to create it
  await api.transfer({ account: evmNormalAccount, sender: sender.address, to: receiver, quantity: `0.0001 ${SYSTEM_SYMBOL}` })

  // Transfer 1000 FIRE ERC20 tokens
  await api.eth.transfer(receiver, 1000, { sender: sender.address })

  // Query ERC20 FIRE balance using "view" function calls
  console.log(`${sender.address} Balance:`, +(await api.eth.balanceOf(sender.address)).toString(10), 'FIRE') // 999,000
  console.log(`${receiver} Balance:`,       +(await api.eth.balanceOf(receiver)).toString(10), 'FIRE'), //   1,000

  // Set allowance, and modify it
  await api.eth.approve(receiver, 100, { sender: sender.address })
  await api.eth.increaseAllowance(receiver, 1000, { sender: sender.address })
  await api.eth.decreaseAllowance(receiver, 600, { sender: sender.address })

  // Query allowance (another example of using non-state modifying calls)
  const allowance = await api.eth.allowance(sender.address, receiver, { sender: receiver })
  console.log(`Allowance for ${sender.address}->${receiver}:`, +allowance.toString(10), 'FIRE') // 500

  // Use the allowance to transfer
  // rawSign uses ethereum private key to sign instead of EOSIO account permissions
  await api.eth.transferFrom(sender.address, receiver, 500, { sender: receiver, rawSign: true })

  // Withdraw tokens
  await api.telos.withdraw({ account: evmNormalAccount, quantity: `0.0001 ${SYSTEM_SYMBOL}` })

  // Other available functions, check docs
  // await getStorageAt(address, key)
  // await createEthTx({ sender, data, gasLimit, value, to, rawSign = false })
  // async getNonce(address)
  // async getEthAccount(address)
}

main()

API

Table of Contents