From 9b182c1bd58150cc21e5b20737c0707def5fe06d Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 2 Feb 2024 15:23:17 +0530 Subject: [PATCH 1/4] add chain id method --- libs/remix-simulator/src/methods/accounts.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/remix-simulator/src/methods/accounts.ts b/libs/remix-simulator/src/methods/accounts.ts index 00b8701da3..49be664d19 100644 --- a/libs/remix-simulator/src/methods/accounts.ts +++ b/libs/remix-simulator/src/methods/accounts.ts @@ -71,7 +71,8 @@ export class Web3Accounts { return { eth_accounts: this.eth_accounts.bind(this), eth_getBalance: this.eth_getBalance.bind(this), - eth_sign: this.eth_sign.bind(this) + eth_sign: this.eth_sign.bind(this), + eth_chainId: this.eth_chainId.bind(this) } } @@ -103,4 +104,8 @@ export class Web3Accounts { cb(null, data.signature) } + + eth_chainId (_payload, cb) { + return cb(null, 1337) + } } From 35e4530e6190571b4cd70e96f7ad8b22e039ca55 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 5 Feb 2024 17:01:49 +0530 Subject: [PATCH 2/4] fix method call error --- apps/remix-ide/src/app/tabs/web3-provider.js | 7 ++++++- libs/remix-simulator/src/methods/accounts.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/web3-provider.js b/apps/remix-ide/src/app/tabs/web3-provider.js index 89b7528739..1489e8e37a 100644 --- a/apps/remix-ide/src/app/tabs/web3-provider.js +++ b/apps/remix-ide/src/app/tabs/web3-provider.js @@ -1,6 +1,7 @@ import { Plugin } from '@remixproject/engine' import * as packageJson from '../../../../../package.json' import {isBigInt} from 'web3-validator' +import { addressToString } from "@remix-ui/helper" export const profile = { name: 'web3Provider', @@ -55,7 +56,11 @@ export class Web3ProviderModule extends Plugin { return } const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) - if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) + if (contractData) { + this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) + const data = await this.call('compilerArtefacts', 'getCompilerAbstract', contractData.file) + await this.call('compilerArtefacts', 'addResolvedContract', addressToString(receipt.contractAddress), data) + } }, 50) } } diff --git a/libs/remix-simulator/src/methods/accounts.ts b/libs/remix-simulator/src/methods/accounts.ts index 49be664d19..62a8411a0d 100644 --- a/libs/remix-simulator/src/methods/accounts.ts +++ b/libs/remix-simulator/src/methods/accounts.ts @@ -106,6 +106,6 @@ export class Web3Accounts { } eth_chainId (_payload, cb) { - return cb(null, 1337) + return cb(null, '0x539') // 0x539 is hex of 1337 } } From 94002179cc21e5fb35e8c2f760b54ad5c4b9fec3 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 9 Feb 2024 18:27:54 +0530 Subject: [PATCH 3/4] fix dot at balance end --- apps/remix-ide/src/blockchain/providers/injected.ts | 3 ++- apps/remix-ide/src/blockchain/providers/node.ts | 3 ++- apps/remix-ide/src/blockchain/providers/vm.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/injected.ts b/apps/remix-ide/src/blockchain/providers/injected.ts index 76c211a0ff..32b4938f70 100644 --- a/apps/remix-ide/src/blockchain/providers/injected.ts +++ b/apps/remix-ide/src/blockchain/providers/injected.ts @@ -29,7 +29,8 @@ export class InjectedProvider { async getBalanceInEther (address) { const balance = await this.executionContext.web3().eth.getBalance(address) - return Web3.utils.fromWei(balance.toString(10), 'ether') + const balInString = balance.toString(10) + return balInString === '0' ? balInString : Web3.utils.fromWei(balInString, 'ether') } getGasPrice (cb) { diff --git a/apps/remix-ide/src/blockchain/providers/node.ts b/apps/remix-ide/src/blockchain/providers/node.ts index 1dcf1b6c40..c77421e045 100644 --- a/apps/remix-ide/src/blockchain/providers/node.ts +++ b/apps/remix-ide/src/blockchain/providers/node.ts @@ -35,7 +35,8 @@ export class NodeProvider { async getBalanceInEther (address) { const balance = await this.executionContext.web3().eth.getBalance(address) - return Web3.utils.fromWei(balance.toString(10), 'ether') + const balInString = balance.toString(10) + return balInString === '0' ? balInString : Web3.utils.fromWei(balInString, 'ether') } getGasPrice (cb) { diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index 3ae7f6a154..67357b347e 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -97,7 +97,8 @@ export class VMProvider { async getBalanceInEther (address) { const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }) - return fromWei(toBigInt(balance).toString(10), 'ether') + const balInString = toBigInt(balance).toString(10) + return balInString === '0' ? balInString : fromWei(balInString, 'ether') } getGasPrice (cb) { From 081359df35fc93842effbb9d53eff93948abe81c Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 12 Feb 2024 17:52:16 +0100 Subject: [PATCH 4/4] use addressToString for all --- apps/remix-ide/src/app/tabs/web3-provider.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/web3-provider.js b/apps/remix-ide/src/app/tabs/web3-provider.js index 1489e8e37a..16c3a3dd17 100644 --- a/apps/remix-ide/src/app/tabs/web3-provider.js +++ b/apps/remix-ide/src/app/tabs/web3-provider.js @@ -55,11 +55,12 @@ export class Web3ProviderModule extends Plugin { console.log('receipt available but contract address not present', receipt) return } - const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) + const contractAddressStr = addressToString(receipt.contractAddress) + const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', contractAddressStr) if (contractData) { - this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) + this.call('udapp', 'addInstance', contractAddressStr, contractData.contract.abi, contractData.name) const data = await this.call('compilerArtefacts', 'getCompilerAbstract', contractData.file) - await this.call('compilerArtefacts', 'addResolvedContract', addressToString(receipt.contractAddress), data) + await this.call('compilerArtefacts', 'addResolvedContract', contractAddressStr, data) } }, 50) }