Questions tagged [web3js]

Javascript API and library for Ethereum To develop applications on Ethereum, you can use the web3 object provided by the web3.js library. Under the hood it communicates to a local node through RPC calls. web3.js works with any Ethereum node, which exposes an RPC layer. https://github.com/ethereum/wiki/wiki/JavaScript-API

Filter by
Sorted by
Tagged with
2
votes
4answers
2k views

How do I install web3@1.0.-beta.26 on Windows 10?

How do I install web3@1.0.-beta.26 on Windows 10? npm install --save web3@1.0.0-beta.26 does not work and creates a page of errors. I've also tried --python=python2.7 Here is what I get. C:\Users\...
2
votes
0answers
1k views

web3.js Error: the method personal_listAccounts does not exist/is not available [duplicate]

Code: var Web3 = require('web3'); var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); var sender = web3.eth.accounts[0]; console.log('Sender: ' + sender); web3.personal....
2
votes
1answer
2k views

Web3 not defined

I am following this tutorial here: https://medium.com/@merunasgrincalaitis/the-ultimate-end-to-end-tutorial-to-create-and-deploy-a-fully-descentralized-dapp-in-ethereum-18f0cf6d7e0e after running ...
2
votes
2answers
1k views

Truffle test error: Cannot create instance of Vault; no code at address

I'm trying to make a simple test in Truffle using Ganache where I call a function from a smart contract instance. This component will create a Vault and return me its address. My truffle test does ...
2
votes
2answers
953 views

How to send transaction/call function from server-side?

After an event emits from my smart contract and I hear it server-side, I want to call a certain function in the smart contract and pass it some information to use. I'm wondering how you place a ...
2
votes
3answers
454 views

Why is my transaction not performing?

I wrote the following script to send Ether. I can't figure out why the balance is still the same after I send out the Ether. I re run this script multiple times but nothing changes with the balance. ...
1
vote
2answers
415 views

Invalid Op Code - passing bytes32 array to a contract method called from another method of another contract

I've been banging my head on this one for some hours, I'd appreciate any help :) This is a final edit to clearly state the issue: Is there a proper way to pass a bytes32 array to a method on contract ...
1
vote
1answer
488 views

what happens when require() is false

From what I under stands when the condition in require() is not met solidity performs revert operation. Right? What I want to know is how can we handle this in web3. That is if i have a function in ...
1
vote
1answer
468 views

How do I get all logs for all time for a given contract using web3?

This answer worked when filter.get was not deprecated, but now I am not sure how to do the same thing with subscribe - web3.eth.subscribe hears new events and acts on them after I create the ...
1
vote
1answer
98 views

Node error when I deployed smart contract - Web3.js

I get this error when I deployed smart contract to my private chain. Error: Node error: {"code":-32000,"message":"unknown account"} This is my web3.js code. const bytecode = "...
1
vote
1answer
147 views

Bundling web3js does not seem to work (Metamask app)

(This is a follow-up question from here.) From the Metamask developers faq it is stated to "bundle the version of web3 that is used during development". So I downloaded a web3.min.js version 0.20.6 ...
1
vote
2answers
574 views

web3 - Error when calling sendTransaction with @truffle/contract on Ropsten Infura

My smart contract is already deployed on Ropsten TestNet provided by Infura at 0x63865E0F065C7b865e1a2EE4d99C383A414Bec22 address. I want to sendTransaction using NodeJS(v.10.16.1) + Web3(v.1.2.6) + @...
1
vote
1answer
348 views

Handling require/assert failure errors correctly from a Node.JS app?

I have a getter function in my smart contract that returns one of the string values in statically defined string array. Upon entry to the function, it does a bounds check on the incoming index using ...
1
vote
0answers
602 views

Ganache is not showing any events

I have a contract method which emits events but ganache seems not to catch any events. I say this because when I deploy my contract on ropsten the events are being caught fine but only in ganache I ...
1
vote
1answer
1k views

When is a transaction callback called?

Is the callback of a myContractMethod.sendTransaction(/* ... */) called as soon as the the transaction is sent to the network or once it is mined? Related posts Here are some related references I ...
1
vote
1answer
280 views

Solidity and Web3js codes are not working inside the private Ethereum(geth) network but same codes are working in public ethereum

geth version : 1.9.0-stable-52f24617, node version : v10.16.3, npm version : 6.9.0, web3 version : -- web3@1.0.0-beta.36. genesis.json: { "config": { "chainId": 9663080, "homesteadBlock": 0, "...
1
vote
4answers
3k views

Connecting to local blockchain using web3 and HttpProvider

I wrote an application to connect to the local blockchain. Here is the code: var Web3 = require('web3'); var contract = require('./PublishService_abi.js'); var PublishServiceContract; var web3 = new ...
1
vote
0answers
457 views

Error: Cross origin null forbidden : ---Problem in downloading Open source contracts from Etherscan.io

UPDATED: I am trying to download source code of open source verified contract from Etherscan.io. Here is my procedure as directed by Ann. 1. Download CSV file of captioned contracts. 2. Write ...
1
vote
3answers
891 views

Web3.Utils - WeiToEth and EthToWei Conversion choking on decimals

I have the following two helper functions. It was based on a course I'm going through, so I didn't think I would have to debug them. I don't understand why it works with whole numbers, but not with ...
1
vote
2answers
4k views

How can I get the current user account selected in MetaMask with Web3 js?

I'm using the next function to get the first account from user's MetaMask: var account = web3.eth.getAccounts((error,result) => { if (error) { console.log(error); } ...
1
vote
0answers
164 views

Multithreading in web3.js [duplicate]

Is it possible to run concurrent tasks using web3.js and an Ethereum client? For example, say we have the following code to iterate through a number of blocks: var startBlockNumber = 0; var ...
1
vote
1answer
540 views

Account balance does not decrease after send ether

For example here is my example function in smart contract: function adoptCreeptomas(uint256 beastQuantity, address referrer ) public payable whenNotPaused { msg.sender.transfer(50); } And then I ...
1
vote
3answers
2k views

authentication needed: password or unlock

We're using Microsoft Azure, and NodeJS on the server. When we address Microsoft Azure via NodeJS, sometimes we get the 'Password or Unlock' error. But when we use Truffle and address the same setter, ...
1
vote
1answer
685 views

How to scan ether transfer from smart contract to my addresses programmatically?

Correct me if I am wrong, the transaction receipt contains only the log of contract events. So we can only use it to examine the internal transaction that produces a event. How about ether transfer ...
1
vote
1answer
63 views

how to interact with an already deployed smart contract

I was reading this contract https://docs.soliditylang.org/en/develop/solidity-by-example.html#safe-remote-purchase that I found in the solidity documentation and I assume this contract is unique and ...
1
vote
2answers
3k views

Unable to npm install web3 on Windows 10

I followed every thing on this page : https://medium.com/@PrateeshNanada/steps-to-install-testrpc-in-windows-10-96989a6cd594 Except step number 5 where my Node.js version is 8.10.0 instead of 8.10.2 ...
1
vote
1answer
403 views

Call contract view method from web3

I am trying to call a function on a smart contract using web3 and web3-eth-contract but I get the error Provider does not have a request or send method to use. Here is the general code I am attempting:...
1
vote
0answers
110 views

Removing LP from Uniswap/Pancake using seth and removeLiquidityWithPermit(). How is the correct hash for the permission signing calculated?

I'm trying to figure out how I can remove LPs from Uniswap/Pancakeswap using the function removeLiquidityWithPermit(address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 ...
1
vote
1answer
84 views

How to identify token transfers looking at a transaction?

Let's take this transaction as an example. If I use web3js getTransaction method and decode the payload, it will give me information such as: { blockHash: null, blockNumber: null, from: '...
1
vote
1answer
199 views

Truffle ganache fork

Suppose I have access to a full archive Node and I want to fork from a specific block using Ganache. Using ganache-cli, I can specify where to fork using the --fork parameter by passing it the Node ...
1
vote
1answer
311 views

Signing a transaction server-side

I want to sign every transaction server side from the same address/wallet through web3. What's the best way to tackle this? Do I need to: first use web3.eth.sendTransaction Use web3.eth.sign to sign ...
1
vote
2answers
184 views

Web3's eth_sign with metamask notification never closes and promise doesn't resolve!

I'm trying to call web3's eth_sign with metamask's provider, like so var signature = await web3.eth.sign(web3.utils.utf8ToHex(randomMsg),acc0) The metamask windows notification pops up and ...
1
vote
1answer
268 views

How can I determine which transactions have failed using a web3.js call

I am attempting to call transactions that execute methods on a contract in order to collect specific data. I am currently using web3.eth.getTransaction(hash) in order to view the transaction ...
1
vote
3answers
1k views

Using ganache-cli provider causes “Error: Provider not set or invalid”

I'm trying to write and run tests for my smart contract and I get this error: "Error: Provider not set or invalid" Smart contract code: const assert = require('assert'); const ganache = require('...
1
vote
3answers
856 views

How to generate a new Ethereum address and private key from a command line?

How one can securely generate a new raw private key from a UNIX command line? This private key can be then imported to wallet apps or web3.js.
1
vote
1answer
519 views

How to Keccak 256 hash in front end JavaScript before passing it to my smart contract

I would like to build a simple JavaScript (JS) front end that checks if a field submitted is the pre-image of a keccak256 hash I already know in my smart contract. I currently use the following: ...
1
vote
3answers
4k views

How to build and sign a transaction to deploy a contract

I am trying to generate a transaction to deploy a smart contract on the chain and to sign it with web3js. My problem is that I have no idea how to build the transaction object needed for the ...
1
vote
1answer
605 views

How to deploy Smart Contracts With Web3 Using Async/Await?

This is my Javascript code. I keep getting an error that states Error: No privateKey given to the TransactionSigner. at TransactionSigner._callee$ (/Users/payton/WebstormProjects/Esgro_DAPP/...
1
vote
0answers
102 views

error in WebSocket connection

error : browser-sync-client.js?v=2.26.3:15 WebSocket connection to 'ws://localhost:3000/browser-sync/socket.io/?EIO=3&transport=websocket&sid=mW3 please i need help on this. i was getting ...
1
vote
1answer
1k views

Web3J: TypeError: MyContract is not a constructor

I am simply trying to call my contracts on a private blockchain from a nodeJS app after a call from the browser but I keep getting this error in my node: 2017-03-01T21:07:34.782560+00:00 app[web.1]: ...
1
vote
1answer
1k views

Synchronous requests are not supported by the IPC provider

I was trying to connect to my node via IPC using web3_ipc. But i got hit by: You tried to send "eth_getBalance" synchronously. Synchronous requests are not supported by the IPC provider. My code is ...
1
vote
1answer
3k views

How to use sendTransaction to send ERC20 tokens through Metamask?

I have a custom ERC20 token and I want to enable metamask support. By this I mean: 1) The user clicks a "Pay using metamask" button 2) The Metamask payment window pops up and with "Pay 100 ABC ...
1
vote
0answers
189 views

Insufficient funds when using 'signTransaction' but not when using 'unlockAccount'

I am trying to execute a transaction on a private network, using my account. The general flow: Web3.js --> Parity node --> Private network The transaction: Invoke a method in a contract ...
1
vote
0answers
351 views

Mocha timeout, not resolving promise of large array from method.mymethod.call()

I'm trying to test a contract getter method that returns a large array. I am testing using the web3 library in Mocha with ganache-cli provider. My contract deploys alright, but trying to call the ...
1
vote
2answers
1k views

Cannot find module 'web3' meteor

I am trying to use the web3 API through my project in meteor. I saw an example that included web3 the following way: <script type="text/javascript"> var Web3 = require('web3'); var web3 = new ...
1
vote
2answers
262 views

How to safely node.js script which uses geth, without risking external actors accessing it with --rpc?

So if I want to write a script which uses geth and web3, the first that comes to mind is starting geth with --rpc enabled. Will this risk the wallet being accessed from outside? Is there a way of ...
1
vote
1answer
2k views

Getting 'base fee exceeds gas limit' on a transaction which requires a small amount of gas

I have the following contract: pragma solidity ^0.4.24; contract MyContract { address public owner; bool public unlocked; constructor() public { owner = msg.sender; ...
1
vote
1answer
162 views

why are return values only True or False

Return values from functions which create transactions, can only be true or false, at least when you check them post transaction (e.g., with web3 through receipt). However, when functions call each ...
1
vote
1answer
458 views

Accessing/Modifying Options Parameters in Contract

I'm using truffle and metamask to deploy a very simple contract that enables the transfer of ether from one test account to another. How do I use my JavaScript file to access the options parameters ...
1
vote
3answers
678 views

Cors Error with Infura?

anyone else who tries to read smart contract data through Infura and process it on front-end but gets 'CORS' error? My DAPP works fine in Google Chrome and has no issue in fetching the smart contract ...