Skip to content

web3.js plugin for aurora-is-near engine

License

Notifications You must be signed in to change notification settings

Con3X/web3-plugin-aurora

Repository files navigation

web3.js plugin for Aurora NEAR engine

Dependency Status

This is an npm package containing a web3.js plugin for Aurora NEAR engine.

Aurora is an EVM-compatible blockchain built as a smart contract atop NEAR blockchain. This plugin would leverage Aurora custom RPC methods. And it also do not display the unsupported methods. The Aurora supported RPC methods are listed at: https://doc.aurora.dev/evm/rpc/. And the most updated version is at: https://github.com/aurora-is-near/relayer2-public?tab=readme-ov-file#json-rpc-methods.

Plugin usage by users

At your typescript project first run: yarn add web3 @con3x/web3-plugin-aurora

And here is how to use the plugin:

import { Web3 } from 'web3';
import { AuroraPlugin } from '@con3x/web3-plugin-aurora';

async function aurora() {
  const web3 = new Web3('https://mainnet.aurora.dev');
  web3.registerPlugin(new AuroraPlugin(web3.provider));

  const blockNumber = await web3.aurora.eth.getBlockNumber();
  console.log('aurora blockNumber', blockNumber);

  const parityPendingTransactions =
    await web3.aurora.parity.pendingTransactions();
  console.log('aurora parity_pendingTransactions', parityPendingTransactions);
}

aurora();

You can play with the npm package online at: https://codesandbox.io/p/devbox/testing-web3-plugin-aurora-v7249s?file=%2Findex.js

Supported RPC Methods

Here are all RPC methods and how to call them using the plugin. The original table of RPC methods is from: https://doc.aurora.dev/evm/rpc/ :

Method How to call Comments
web3_clientVersion web3.aurora.web3.clientVersion() Same as calling eth.getNodeInfo()
web3_sha3 web3.aurora.web3.sha3(value) It supposes to provide the same result as calling web3.utils.sha3
net_listening web3.aurora.net.isListening()
net_peerCount web3.aurora.net.getPeerCount()
net_version web3.aurora.net.getId()
eth_accounts web3.aurora.eth.getAccounts()
eth_blockNumber web3.aurora.eth.getBlockNumber()
eth_call web3.aurora.eth.call({
  to: contractAddress,
  input: '0x...')
})
eth_chainId web3.aurora.eth.getChainId()
eth_coinbase web3.aurora.eth.getCoinbase()
eth_compileLLL Unsupported
eth_compileSerpent Unsupported
eth_compileSolidity Unsupported
eth_estimateGas web3.aurora.eth.estimateGas(transaction)
eth_gasPrice web3.aurora.eth.getGasPrice()
eth_getBalance web3.aurora.eth.getBalance(address)
eth_getBlockByHash web3.aurora.eth.getBlock(blockHash)
eth_getBlockByNumber web3.aurora.eth.getBlock(blockNumber)
eth_getBlockTransactionCountByHash web3.aurora.eth.getBlockTransactionCount(blockHash)
eth_getBlockTransactionCountByNumber web3.aurora.eth.getBlockTransactionCount(blockNumber)
eth_getCode web3.aurora.eth.getCode(address)
eth_getCompilers web3.aurora.eth.getCompilers()
eth_getFilterChanges web3.aurora.eth.getFilterChanges(filterId)
eth_getFilterLogs web3.aurora.eth.getFilterLogs(filterId)
eth_getLogs web3.aurora.eth.getPastLogs(filter)
eth_getProof EIP-1186
eth_getStorageAt web3.aurora.eth.getStorageAt(address, storageSlot)
eth_getTransactionByBlockHashAndIndex web3.aurora.eth.getTransactionFromBlock(blockHash, transactionIndex)
eth_getTransactionByBlockNumberAndIndex web3.aurora.eth.getTransactionFromBlock(blockNumber, transactionIndex)
eth_getTransactionByHash web3.aurora.eth.getTransaction(transactionHash)
eth_getTransactionCount web3.aurora.eth.getTransactionCount(address [, block])
eth_getTransactionReceipt web3.aurora.eth.getTransactionReceipt(transactionHash)
eth_getUncleByBlockHashAndIndex web3.aurora.eth.getUncle(blockHash, uncleIndex)
eth_getUncleByBlockNumberAndIndex web3.aurora.eth.getUncle(blockNumberOrTag, uncleIndex)
eth_getUncleCountByBlockHash web3.aurora.eth.getBlockUncleCount(blockHash)
eth_getUncleCountByBlockNumber web3.aurora.eth.getBlockUncleCount(blockNumber)
eth_getWork Unsupported
eth_hashrate web3.aurora.eth.getHashRate()
eth_mining web3.aurora.eth.isMining()
eth_newBlockFilter web3.aurora.eth.newBlockFilter()
eth_newFilter web3.aurora.eth.newFilter()
eth_newPendingTransactionFilter web3.aurora.eth.newPendingTransactionFilter()
eth_pendingTransactions web3.aurora.eth.getPendingTransactions()
eth_protocolVersion web3.aurora.eth.getProtocolVersion()
eth_sendRawTransaction web3.aurora.eth.sendSignedTransaction(tx)
eth_sendTransaction Unsupported
eth_sign
eth_signTransaction Unsupported
eth_signTypedData Unsupported
eth_submitHashrate Unsupported
eth_submitWork Unsupported
eth_syncing web3.aurora.eth.isSyncing()
eth_uninstallFilter web3.aurora.eth.uninstallFilter(filterId)
db_getHex Deprecated
db_getString Deprecated
db_putHex Deprecated
db_putString Deprecated
shh_addToGroup Discontinued
shh_getFilterChanges Discontinued
shh_getMessages Discontinued
shh_hasIdentity Discontinued
shh_newFilter Discontinued
shh_newGroup Discontinued
shh_newIdentity Discontinued
shh_post Discontinued
shh_uninstallFilter Discontinued
shh_version Discontinued
txpool_content Unsupported
txpool_inspect Unsupported
txpool_status Unsupported
parity_pendingTransactions web3.aurora.parity.pendingTransactions() Parity extension

Project progress:

NEAR Aurora Plugin

Create NEAR Aurora Plugin and publish it to the npm registry

The web3.js plugin for NEAR Aurora has been publish to
https://www.npmjs.com/package/@con3x/web3-plugin-aurora and it is useable inside this example playground: https://codesandbox.io/p/sandbox/misty-leftpad-v7249s?file=%2Findex.js. Additionally, some tests has been written to test some of the basic functionality.

web3.aurora is also accessible as web3.near.aurora

Aurora plugin could be used also as web3.near.aurora.

const web3 = new Web3("https://mainnet.aurora.dev");

const nearPlugin = new NearPlugin();
// registering the NearPlugin has to be done before registering the AuroraPlugin
// this will allow the provider to be passed from the Web3 instance to NearPlugin to AuroraPlugin
web3.registerPlugin(nearPlugin);
nearPlugin.registerPlugin(new AuroraPlugin());

const result = await web3.near.aurora.eth.getBlockNumber();

Enable all Ethereum RPC methods on AuroraPlugin

Now all Ethereum RPC methods are callable on web3.aurora.eth (and on web3.near.aurora.eth as a consequence). Additionally, all not-supported methods are not exposed as callable methods.

Support all RPC methods on AuroraPlugin organized in namespaces

NEAR Plugin

There is a web3.js plugin for the NEAR protocol. Check its repository at: https://github.com/con3x/web3-plugin-near

Running Tests

Testing AuroraPlugin

Executing yarn test aurora.test.ts would give something like:

 PASS  test/aurora.test.ts (42.118 s)
  AuroraPlugin Tests
    AuroraPlugin can call `web3` endpoints
      ✓ should be able to call `web3_clientVersion` (4264 ms)
      ✓ should be able to call `web3_sha3` (691 ms)
    AuroraPlugin can call `net` RPC endpoints
      ✓ should be able to call `net_listening` method (669 ms)
      ✓ should be able to call `net_peerCount` method (685 ms)
      ✓ should be able to call `net_version` method (670 ms)
    AuroraPlugin can call Ethereum standard RPC endpoints
      ✓ should be able to call `eth_accounts` method with expected param (1315 ms)
      ✓ should be able to call `eth_blockNumber` method with expected param (734 ms)
      ✓ should be able to call `eth_call` method with expected params (700 ms)
      ✓ should be able to call `eth_chainId` method with expected param (688 ms)
      ✓ should be able to call `eth_coinbase` method with expected param (684 ms)
      ✓ should be able to call `eth_estimateGas` method with expected param (1690 ms)
      ✓ should be able to call `eth_gasPrice` method with expected param (748 ms)
      ✓ should be able to call `eth_getBalance` method with expected param (692 ms)
      ✓ should be able to call `eth_getBlockByHash` method with expected param (3718 ms)
      ✓ should be able to call `eth_getBlockByNumber` method with expected param (1515 ms)
      ✓ should be able to call `eth_getBlockTransactionCountByHash` method with expected param (695 ms)
      ✓ should be able to call `eth_getBlockTransactionCountByNumber` method with expected param (706 ms)
      ✓ should be able to call `eth_getCode` (777 ms)
      ✓ should be able to call `eth_getCompilers` (1710 ms)
      ✓ should be able to call `eth_getFilterChanges` (1989 ms)
      ✓ should be able to call `eth_getFilterLogs` (1354 ms)
      ✓ should be able to call `eth_getLogs` (694 ms)
      ✓ should be able to call `eth_newFilter` (1343 ms)
      ✓ should be able to call `eth_protocolVersion` (676 ms)
      ✓ should be able to call `eth_syncing` (625 ms)
      ✓ should be able to call `eth_uninstallFilter` (3813 ms)
      ✓ should be able to call `eth_gasPrice` (714 ms)
      ✓ should be able to call `eth_coinbase` (745 ms)
      ✓ should be able to call `eth_getBalance` (2826 ms)
      ✓ should be able to call `eth_getCompilers` (660 ms)
      ✓ should calling `eth_getProof` throws (1 ms)
      ✓ should calling `eth_getWork` throws (1 ms)
      ✓ should have the rest of the methods at web3.aurora.eth all available (6 ms)
      ✓ should have the unavailable  methods at web3.aurora.eth as undefined (2 ms)
    AuroraPlugin can call `parity` endpoints
      ✓ should be able to call `parity_pendingTransactions` (1857 ms)
Test Suites: 1 passed, 1 total
Tests:       3 skipped, 35 passed, 38 total
Snapshots:   0 total
Time:        42.151 s

Executing yarn test near.aurora.test.ts would give something like:

 PASS  test/near.aurora.test.ts
  web3.near.aurora Tests
    ✓ should have `web3.near.aurora` setup (1 ms)
    ✓ should call `getBlockNumber` method on `web3.near.aurora.eth` (395 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        2.658 s, estimated 3 s

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

And for your proposed changes, please make sure to add and/or update tests as needed.

About

web3.js plugin for aurora-is-near engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published