Skip to content

Commit 04318fc

Browse files
authored
Merge pull request #4511 from ethereum/fix4185
fix errors while contract deployment using script
2 parents 0287bee + efb2ec1 commit 04318fc

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

apps/remix-ide/src/app/tabs/web3-provider.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Plugin } from '@remixproject/engine'
22
import * as packageJson from '../../../../../package.json'
33
import {isBigInt} from 'web3-validator'
4+
import { addressToString } from "@remix-ui/helper"
45

56
export const profile = {
67
name: 'web3Provider',
@@ -54,8 +55,13 @@ export class Web3ProviderModule extends Plugin {
5455
console.log('receipt available but contract address not present', receipt)
5556
return
5657
}
57-
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress)
58-
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
58+
const contractAddressStr = addressToString(receipt.contractAddress)
59+
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', contractAddressStr)
60+
if (contractData) {
61+
this.call('udapp', 'addInstance', contractAddressStr, contractData.contract.abi, contractData.name)
62+
const data = await this.call('compilerArtefacts', 'getCompilerAbstract', contractData.file)
63+
await this.call('compilerArtefacts', 'addResolvedContract', contractAddressStr, data)
64+
}
5965
}, 50)
6066
}
6167
}

apps/remix-ide/src/blockchain/providers/injected.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export class InjectedProvider {
2929

3030
async getBalanceInEther (address) {
3131
const balance = await this.executionContext.web3().eth.getBalance(address)
32-
return Web3.utils.fromWei(balance.toString(10), 'ether')
32+
const balInString = balance.toString(10)
33+
return balInString === '0' ? balInString : Web3.utils.fromWei(balInString, 'ether')
3334
}
3435

3536
getGasPrice (cb) {

apps/remix-ide/src/blockchain/providers/node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class NodeProvider {
3535

3636
async getBalanceInEther (address) {
3737
const balance = await this.executionContext.web3().eth.getBalance(address)
38-
return Web3.utils.fromWei(balance.toString(10), 'ether')
38+
const balInString = balance.toString(10)
39+
return balInString === '0' ? balInString : Web3.utils.fromWei(balInString, 'ether')
3940
}
4041

4142
getGasPrice (cb) {

apps/remix-ide/src/blockchain/providers/vm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export class VMProvider {
9797

9898
async getBalanceInEther (address) {
9999
const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX })
100-
return fromWei(toBigInt(balance).toString(10), 'ether')
100+
const balInString = toBigInt(balance).toString(10)
101+
return balInString === '0' ? balInString : fromWei(balInString, 'ether')
101102
}
102103

103104
getGasPrice (cb) {

libs/remix-simulator/src/methods/accounts.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export class Web3Accounts {
7171
return {
7272
eth_accounts: this.eth_accounts.bind(this),
7373
eth_getBalance: this.eth_getBalance.bind(this),
74-
eth_sign: this.eth_sign.bind(this)
74+
eth_sign: this.eth_sign.bind(this),
75+
eth_chainId: this.eth_chainId.bind(this)
7576
}
7677
}
7778

@@ -103,4 +104,8 @@ export class Web3Accounts {
103104

104105
cb(null, data.signature)
105106
}
107+
108+
eth_chainId (_payload, cb) {
109+
return cb(null, '0x539') // 0x539 is hex of 1337
110+
}
106111
}

0 commit comments

Comments
 (0)