New answers tagged

1

The --rpc.txfeecap param on node should be changed to 0: --rpc.txfeecap value Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) (default: 1) info - https://geth.ethereum.org/docs/interface/command-line-options


0

In your estimate gas query, the gas price mostly doesn't play a role, unless the smart contract you're interacting with is using 0x3A (`` opcode) for some logic. The logic of swapExactETHForTokens doesn't use GASPRICE, so even if you pass gasPrice as 0, it wouldn't effect the estimation. And hence, you can get the estimation even if you have no ETH in your ...


0

Yes, you can use ethers.js in your Node.js environment to deploy or interact with your contract on the ethereum network. You can find the relevant documentation here. As an example: const jsonFile = require('./path/to/my_specific_library.json'); // deploying const myContractFactory = new ethers.ContractFactory(jsonFile.abi, jsonFile.evm.bytecode, signer); ...


0

Your formatting is just off with the call. The Solidity Documentation details this as the way to do this: address(nameReg).call{gas: 1000000}(abi.encodeWithSignature("register(string)", "MyName")); So you should change your code to be: return to.call{value:value, gas:gaslimit}(data);


0

The web3 api doesn't natively support connections to multiple blockchains at once, so you would need to initialize another web3 object using a node url that is on the network you want to query. You can then manage both web3 objects and query both networks.


1

I found out my question was answered here: Sending an ethereum transaction with ethers.js and metamask The real issue was that the account I was sending ETH to on the mainnet fork was a contract address with a fallback function that didn't allow it to accept ETH.


1

I was able to use ethers.utils.formatEther( value ) ⇒ string to convert back to readable.


1

You need your smart contract address, your ABI and web3js. But you need also a node that actually work with ethereum blockchain. You can do your local node (but it will take long time to sync and a very large memory space) or you can use Infura.io that give you API key so they send to you event from the blockchain.


0

const BigNumber = require('bignumber.js'); let num=new BigNumber(1252500000000000000) let denom = new BigNumber(10).pow(16) let ans = num.dividedBy(denom).toNumber() console.log(ans) Hope this explains your question.For further info,refer https://mikemcl.github.io/bignumber.js/


0

Well.... I fixed my issue. Turns out it was failing because i was using a bytes32 instead of a string for the argument. i cant really explain why this happened incase anyone else can


2

Replace "=" with "==" in require statement : require(msg.sender == data[i].owner, "Sender is not owner.");


1

This is a SERIOUSLY painful way to take. The router contract has functions called getAmountsOut and getAmountsIn, use them. Simply pass in the token path&amount inputted or outputted and it will return the amount you would receive if that tx were to happen. It accounts for price impact itself, you don't have to worry about that.


1

After some research & testing I found the solution by mysef. As a fallback function is unnamed, I just need to use estimateGas with the "eth" object to get the gas stimation of the default function (fallback): const web3eth = require('web3-eth'); const eth = new web3eth('https://ropsten.infura.io/v3/XXXXXXX'); var tx = {}; tx.gas; eth....


0

For Binance smart chain testnet it worked fine: const createRawTransaction = require('ethereumjs-tx').Transaction; const common = require('ethereumjs-common'); const chain = common.default.forCustomChain( 'mainnet',{ name: 'bnb', networkId: 97, chainId: 97 }, ...


-1

It returns the gas limit, not the gas price. Gas limit is how many units of gas to use at most, and a unit of gas is your gas price.


1

I had to read how the pancakeswap frontend does this. Basically, you calculate gas for BOTH methods. And the one that does not return an error, is the one you use. e.g: contract.methods.swapExactTokensForETHSupportingFeeOnTransferTokens( Web3.utils.toHex(amountIn), Web3.utils.toHex(0), path, to, deadline ).estimateGas({ from: activeAccount.address, gas:...


0

What is your setup environment? Hardhat? Truffle? Using ethers.js or web3.js? Anyway, I just solved it. I am using Hardhat with ethers.js For the error message: 'ProviderError: exceeds the configured cap (1.00 ether)' Solution: The gasPrice was too high. For Rinkeby or Polygon/Matic, set both of the networks' gasPrice to 20e9 and 10e9 respectively in Hardhat ...


0

I'd create a promise that subscribe to the 'block' events and waits for the correct number of blocks. Read the documentation Event Emitter Methods. A pseudo code would be like: await new Promise((resolve, reject) => { provider.on("block", (blockNumber) => { if (blockNumber == desiredBlcok) { resolve(); } }) });


2

You should add the below command after the last line you embedded in the question: myContract.methods.fname().call().then(function(instance){console.log(instance)});


Top 50 recent answers are included