Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix errors while contract deployment using script #4511

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/remix-ide/src/app/tabs/web3-provider.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -54,8 +55,13 @@ 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)
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
const contractAddressStr = addressToString(receipt.contractAddress)
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', contractAddressStr)
if (contractData) {
this.call('udapp', 'addInstance', contractAddressStr, contractData.contract.abi, contractData.name)
const data = await this.call('compilerArtefacts', 'getCompilerAbstract', contractData.file)
await this.call('compilerArtefacts', 'addResolvedContract', contractAddressStr, data)
}
}, 50)
}
}
Expand Down
3 changes: 2 additions & 1 deletion apps/remix-ide/src/blockchain/providers/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion apps/remix-ide/src/blockchain/providers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion apps/remix-ide/src/blockchain/providers/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion libs/remix-simulator/src/methods/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -103,4 +104,8 @@ export class Web3Accounts {

cb(null, data.signature)
}

eth_chainId (_payload, cb) {
return cb(null, '0x539') // 0x539 is hex of 1337
}
}
Loading