New answers tagged

0

It seems to be an issue with invoking with web3 via a nonsecure http connection, although I don't know why. This is what I did to get it to work: Set up an ngrok secure tunnel Run geth as follows: geth --rinkeby --rpc --rpcport=8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*" Use the following URL to connect from anywhere. It works with truffle, geth console, ...


1

Just in case someone comes here later, in the recent version of ethers, HDNODE has been moved to the utils method. So, in modification to @George's answer above; const ethers = require('ethers'); const mnemonic = await ethers.utils.HDNode.entropyToMnemonic(ethers.utils.randomBytes(16)); const wallet = ethers.Wallet.fromMnemonic(mnemonic);


0

FileViewed is an event if you are using web3 v1.2 you have to use like this: marketplace.events.FileViewed({ fromBlock: 0 }, function (error, event) { if (error) { console.log("Error: ", error); } else { console.log("File viewed: ", event); } }) For more details see this: https://web3js.readthedocs.io/en/v1.2.1/web3-eth-...


0

Try: const contract = await new web3.eth.Contract(JSON.parse(interface)) .deploy( { data:"0x"+bytecode} ) .send( { gas: '5000000', from:accounts[0]}); Otherwise please make sure that your accounts array includes actual values.


0

You should pass a string or a BN object, not an integer. Also note that this specific integer (10 ** 18) is larger than Number.MAX_SAFE_INTEGER and should therefore not be used for any other purpose. Here are a few options which you can choose from: const amount = "1e18"; const amount = Web3.utils.toBN("1e18"); const amount = Web3.utils.toBN(10).pow(18); ...


1

javascript cannot handle those big numbers, Use the method web3.utils.toWei(number [, unit]). const amount = web3.utils.toWei(1, 'ether');


0

Average gas price can be calculated (as a median for the last several blocks) by using the following code: web3.eth.getGasPrice().then((result) => { console.log(web3.utils.fromWei(result, 'ether')) })


0

I don't know the infrastructure of your current project. However it is worth to try changing: web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); to: web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.1.37:8545")); You are using geth attach with this IP as well so it might solve your problem. Edit 1: As it seems to ...


0

Adding an answer for others who come across this. Unpopular opinion: Don't do it, because you can't do it. Methods based on the assumption that code size of zero reliably implies that the caller must be an EOA will probably introduce a security risk. This is because a constructor can make such a call the constructor's address will return length 0 because ...


0

You don't get a transaction hash because there is no transaction. If estimateGas reverts, then the actual transaction should revert as well. I don't know of a way to debug estimateGas calls, but you may want to set the properties for estimateGas the same as you will when you actually send the transaction (e.g. set the gas price and from address to what they ...


0

In a project I'm working on I was able to read a return parameter (a transaction "counter") I created in a smart contract by parsing the transaction log with these steps: Web3: Send method to smart contract which emits the counter. This will return the transaction log which is a flat JSON file. Get transaction hash code from: [https://web3js.readthedocs.io/...


1

It's okay to define a contract instance every time you need it, as the ABI and deployed address haven't changed, and your web3 library is only creating a Javascript object off-chain, not checking on-chain or doing anything slow over the network. I think the efficiency difference is negligible, but if you can create your contract instance once and pass it ...


0

You could also do this: async (signed) => { if you want to use shorthand notation.


0

Have you defined mint function as accepting any arguments? If so, I think you need to pass argument(s) like myContract.methods.mint(mintAmount).send({ from: accounts[0] }) .on(“receipt”, receipt => console.log(receipt)) https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#methods-mymethod-send I hope your problem will be solved


1

The solution was to create and add the account from which to send the transaction into a wallet. adding the line web3.eth.accounts.wallet.add('address_private_key') above the method.send() fixed it for me.


0

npm install --global --production windows-build-tools --vs2015 worked for me. As was stated already you can also install Visual Studio 2015/2017 which I had recently uninstalled vs2017 and I started running into a similar issue once I created a new project with web3.


0

Account won't be persistent when you rerun the ganache-cli


0

From the transaction data you used the recipient address as it were the token address. const tx = { from, to: tokenAddress, // <---- You should use tokenAddress instead of eth_address value: '0', gasPrice: web3.utils.toWei('25', 'gwei'), gas: 60000,


0

I believe the issue is this line: web3.utils.toWei(web3.utils.toWei("0.00000001", "ether")) The inner call to web3.utils.toWei returns "10000000000". The outer call defaults to ether as a unit, so it multiplies that by 10**18 again, and you get "10000000000000000000000000000", which is 10,000,000,000 ether, certainly more than you have. Drop the outer ...


0

If it is too difficult for you to use web3.js for managing ERC20 tokens, you might have a look at Tokengateway. It is an easy to use REST API for sending any ERC20 token, get balances for any ERC20 token, get info of any ERC20 token and more. This way there is also no need to setup an own geth node.


0

So this issue was coming up because after adding my accounts to metamask I had to make migrations with truffle migrate and I did not do that. So that was the reason why Metamask had problems connecting to Ganache. New here! So suggestions are welcome! Thanks.


0

As of today(2019/10, web3 1.2.1), the sample code should be updated as below. Note private key should be prefixed with '0x' web3.eth.accounts.recover API is changed Code const signTest = async function(){ // Using eth.sign() let accounts = await web3.eth.getAccounts(); let msg = "Some data" let prefix = "\x19Ethereum Signed Message:\n" + msg.length ...


0

Continuing the comment, you may want to try this: async function func() { var rcAddr = "0x683d1602fa7252d49cda8ac414c1641a56e73d03"; var methodName = "Access Control"; var register = new web3.eth.Contract(rcAbi, rcAddr); var accAddr = await register.methods.getContractAddr(methodName).call({ from: "...


1

Since you are using Truffle you can override the contract's defaults with .defaults() const MyContract = artifacts.require("MyContract.sol") MyContract.defaults({ from: "0x..." }) @truffle/contract documentation (previously named truffle-contract)


0

that error is because you pass account= '' .(in the from:) i think is your web3 version(can you check the version in console with "web3.version") and with web3 1.x.x can you try : web3.currentProvider.selectedAddress to get the address.


0

An uncompressed public key for Ethereum (or any other blockchain that uses the curve secp256k1) uses 64 bytes. You need to store the x and y coordinates which are both 256 bits. A compressed public key is 33 bytes. A parity byte that is and 32 bytes for the x component. The several error you mention are due to the lack of a native type in javascript that ...


1

In short: It's exactly as you suspect, a higher gas limit means your transaction is less likely to be included by miners. The reasoning: miners seek to maximize their profit within each block. Calls to eth_estimateGas can be computationally heavy, so miners typically do not determine the actual gas each tx will consume. Instead they calculate gasPrice * ...


0

How many arguments does the vote method take? In web3.js the smart contract method's arguments are interpreted first, and the last argument is expected to be transaction options such as: { from, gas, gasPrice } If you are supplying a different number of arguments than is expected, web3.js will try to find the from field from an argument where it's not ...


0

This looks like an issue with version 2.0.0 of ethereumjs-tx: https://github.com/ethereumjs/ethereumjs-tx/issues/165 16 You will need to construct your transaction like below: const tx = new Tx(txObject, {chain:'ropsten', hardfork: 'petersburg'})


0

This looks like an issue with version 2.0.0 of ethereumjs-tx: https://github.com/ethereumjs/ethereumjs-tx/issues/165 16 You will need to construct your transaction like below: const tx = new Tx(txObject, {chain:'ropsten', hardfork: 'petersburg'})


0

This looks like an issue with version 2.0.0 of ethereumjs-tx: https://github.com/ethereumjs/ethereumjs-tx/issues/165 16 You will need to construct your transaction like below: const tx = new Tx(txObject, {chain:'ropsten', hardfork: 'petersburg'})


1

The ABI can be converted to a Solidity interface which contains all of the function names: In Python - abi2solc In Javascript - abi2solidity


0

The call to on(...) runs asynchronously (returns immediately). You can fix it as follows: async function task() { const receipts = new Array(length); for (let i = 0; i < length; i++) { feeTx = { ... }; receipts[i] = await web3.eth.sendTransaction(feeTx); } // handle `receipts` here } task(); // do not ...


0

A minified version of the library is always in the dist/ folder in the git repo. Here's the file for version 1.2.1: https://github.com/ethereum/web3.js/tree/v1.2.1/dist


0

It seems you are asking about an ICO. If that's the case, and if you are following something like the OpenZeppelin's implementation, the SOL function you want to call is buyTokens(): function buyTokens(address beneficiary) public nonReentrant payable { uint256 weiAmount = msg.value; _preValidatePurchase(beneficiary, weiAmount); // calculate ...


1

The gas limit for a block is around 8 million, but you tried to send a transaction with a gas limit of 200 million gas.


0

not sure what you ended up doing here, but when I ran into a similar issue, I decided to put web3 into my selectors. That was important because the Provider URL could change over time, so I wanted to make sure that Web3 always had the most up-to-date value from the Redux store. The big perk of doing this as a selector is that you don't need to worry about ...


0

Okay thanks Niklas Feurstein for guiding me through!! I installed windows-build-tools using npm install --global windows-build-tools. Installing git from an outside source (Not npm install git) worked for me. After that npm started working magically fine to install everything I wanted. Also before I was running the command prompt in regular mode but for ...


0

To create a new contract instance pay attention to the uppercase c letter: .Contract() not .contract(). new web3.eth.Contract(jsonInterface[, address][, options])


0

You can check the status field for the correct execution of the contract. The transfer function of ERC-20 either does a successful transaction or reverts. There is no way a transaction succeeds and no token transfer happens ( but it depends on how you write it). But if you need info like sender, recipient, amount, then you can look at the receipt. Just ...


0

Did you try this https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransaction if you see blocknumber it's mean the transaction it's complete


0

I found this way to work. tokenContract.methods.transfer(tAddr, tAmountInWei).send({ from: myAddress, gas: web3.utils.toHex(40000), gasPrice: web3.utils.toHex(25000000000), value: "0x0" }).on('transactionHash', (hash) => { console.log(`txHash: ${hash}`); });


0

In my case, I used private chain, so I could deploy it when I deploy from node address. If you want to deploy from any other address, it is better to use sendTransaction to deploy contract.


0

We can unlock account only for the account that made from web3.eth.personal.newAccount(password, [callback]. If your address is made by in any other way, you don't have to unlock it. You need your privatekey.


0

Interesting question, and I agree with the previous respondent that it's a broad question, and would involve some kind of reputation network and staking, such that people who report false information are penalized by losing their stake, and "truth" is reached by majority vote either by participants or some trusted judges (often called "validators" in Proof-...


0

The maximum gas fees that is allocated for your transaction is gas * gasPrice in your case, it's 25 Gwei (giga-wei, or 10^9 wei, or 10^-9 ETH) times 400,000 gas limit, or 10,000,000 (10^6) Gwei. 10^6 * 10^-9 = 0.001 ETH so your wallet balance should be sufficient. I would double-check two things: call estimateGas to double-check how much gas web3 thinks ...


1

The following Ethereum web wallets are now seeing increasing use alongside Metamask for various dapps, none of which require installing a chrome extension. Portis Fortmatic Torus Democracy <-- the last one is my project For a comparison of why you might use one wallet over another, and general design considerations that go into making a web wallet, I'...


0

Yes, it is a very broad question, so this will be a broad answer. I have lost track of the number of individuals I have encountered who have conceptually mixed up blockchain's "proof" with magical powers that extend into the off-chain world of inputs. This is sometimes called the "onboarding problem" and most applications have it in one form or another. ...


2

To "speed up a transaction" there's only one possible option: to send a new transaction with higher gas price but with the same nonce. This way if nodes see both of the transactions they will most likely pick up the one with the higher gas price and once that is mined the other transaction becomes invalid (a tx with that nonce has already been mined) and is ...


0

In web3 v0.20 there's a utility function that will convert its parameter to BigNumber. For example in your case : const myTokenId = web3.toBigNumber('122164239941406260'); var tx = await nft.mintUniqueTokenTo( receipientAddress, myTokenId, // <- tokenId tokenURI, { from: coinbase } );


Top 50 recent answers are included