From 4ce7228874fdd466b1b0e3284bd4c7a5857f0037 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 19 May 2021 18:06:20 +0530 Subject: [PATCH] hardhat provider plugin --- apps/remix-ide/src/app.js | 5 ++- .../src/app/tabs/hardhat-provider.js | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 apps/remix-ide/src/app/tabs/hardhat-provider.js diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 93dd6753b5..aafc1e8ede 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -29,6 +29,7 @@ const { OffsetToLineColumnConverter } = require('./lib/offsetToLineColumnConvert const QueryParams = require('./lib/query-params') const Storage = remixLib.Storage const RemixDProvider = require('./app/files/remixDProvider') +const HardhatProvider = require('./app/tabs/hardhat-provider') const Config = require('./config') const modalDialogCustom = require('./app/ui/modal-dialog-custom') const modalDialog = require('./app/ui/modaldialog') @@ -296,6 +297,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org makeUdapp(blockchain, compilersArtefacts, (domEl) => terminal.logHtml(domEl)) const contextualListener = new ContextualListener({ editor }) + const hardhatProvider = new HardhatProvider() engine.register([ contentImport, @@ -309,7 +311,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org contextualListener, terminal, web3Provider, - fetchAndCompile + fetchAndCompile, + hardhatProvider ]) // LAYOUT & SYSTEM VIEWS diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js new file mode 100644 index 0000000000..8ebc5e31b8 --- /dev/null +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -0,0 +1,34 @@ +import * as packageJson from '../../../../../package.json' +import { Plugin } from '@remixproject/engine' +import Web3 from 'web3' + +const profile = { + name: 'hardhat-provider', + displayName: 'Hardhat Provider', + kind: 'provider', + description: 'Hardhat provider', + methods: ['sendAsync'], + version: packageJson.version +} + +export default class HardhatProvider extends Plugin { + constructor () { + super(profile) + this.provider = new Web3.providers.HttpProvider('http://127.0.0.1:8545') + } + + sendAsync (data) { + return new Promise((resolve, reject) => { + if (this.provider) { + this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => { + if (error) return reject(error) + resolve(message) + }) + } else { + resolve({"jsonrpc": "2.0", "result": [], "id": data.id}) + } + }) + } +} + +module.exports = HardhatProvider \ No newline at end of file