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
1
vote
2answers
245 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
598 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
0answers
167 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
2answers
369 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
831 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
2answers
165 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
0answers
86 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
414 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
441 views

When creating a new contract I receive a “contract code couldn't be stored” error but the contract is still created

Sale.new({ from: state.account, value: value, gas: 4000000 }).then((instance) => { // do something with instance }).catch((err) => { alert(err) }) When the above code runs I sometimes ...
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
4answers
2k 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 ...
0
votes
2answers
590 views

Why is string getter returning an empty response?

This is a sequence of another question I asked. I have the following contract contract User { string publicKey; function setPublicKey(string _publicKey) onlyOwner { ...
0
votes
1answer
52 views

Web3 1.2.6 appears to ignore require in view function

Given the following function: function checkLock() external view returns (bool) { require( address(this) == IERC721(_nftRegistryAddress).ownerOf(_tokenId), "[...
0
votes
2answers
532 views

how to get contract address after its been mined with web3.js

I have tried to deploy a SmartContract from web3.js node library, I am getting a transaction hash from it but how would I get the contract address after It's been mined by a miner? here is my code ...
0
votes
0answers
124 views

Web3 Websocket Connection To Infura Rinkeby Ropsten

This is my Javascript code. I keep getting an error that states (node:30062) UnhandledPromiseRejectionWarning: TypeError: privateKey.startsWith is not a function I am using node 12.1.0 & ...
0
votes
1answer
74 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: ...
0
votes
1answer
400 views

the tx doesn't have the correct nonce. account has nonce of: 12 tx has nonce of: 3 - Ganache

I am trying to run my simple contract with different parameters (in the form of encoded signatures) and intends to put multiple transaction into ONE block. If I set Ganache GUI with automine option, ...
0
votes
1answer
40 views

Executing an contract via code and without metamask / link an account to JS code to automatically wirte on Ethereum

I'm trying to get my JS-code to call a smart contract on Ethereum (kovan testnet) that will write something on the blockchain and therefore needs ether (actually gas). I called a view function which ...
0
votes
1answer
162 views

Interact with smart contract without metamask

I'm writing an ethereum application that I want to use for an IoT demonstrator. I want to use MQTT to subscribe to an topic and as soon as a signal is transmitted to that topic I want to write ...
0
votes
1answer
98 views

Calling contract functions using only ABI without source code

I have MyContract.json file of some contract(assume i haven't its source code). In .json file, there is abi and bytecode. If i want to deploy such contract (through web3js), I am facing following ...
0
votes
3answers
96 views

How to generate a new Ethereum 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.
0
votes
0answers
31 views

Cant call solidity function from app.js while sending transaction

Solidity function As i want to call function so that oraclize can send query function betOnTeam(uint team) payable public { update(); emit LogInfo("Oraclize query was NOT sent, ...
0
votes
2answers
33 views

Returning a value from an external function

I have in a contract: function createCourt() external returns (uint256) { uint256 _id = ++nonce; courtOwners[_id] = msg.sender; return _id; } Now, when I try to call ...
0
votes
1answer
858 views

Swap ether to tokens on Uniswap V2 Router 02 fails

I am trying to buy DAI tokens from my smart contract using IUniswapV2Router02 contract BuyExample{ IUniswapV2Router02 usi = IUniswapV2Router02(...
0
votes
1answer
87 views

Unable to call methods on my deployed contract

Problem: All method calls to my deployed contract return null Versions: Geth: 1.9.9-unstable Git Commit: c2d65d34d5c6f27b8d1a52280964023a3eefd66e solc: Version: 0.5.13+commit.5b0b510c....
0
votes
2answers
741 views

Web3.js eth.subscribe: on('changed', function(event){}) doesn't work with Metamask?

I write a demo DApp website with this javascript const web3 = new Web3(ethereum); const contractAddr = "0x0Aa27e4B13D5c08A8767B36a0ACb76ED4549B7EA"; const abi = ...; let inst = new ...
0
votes
1answer
216 views

How to download contracts by address from Etherscan using web3.js

I want to download all contracts (open source code) from etherscan.io using Web3js. Etherscan gives only the list of such verified open source contract with txHash, name, and their addresses. Is there ...
0
votes
3answers
2k views

How do I get the return value of a solidity function with web3?

The docs mention using MyContract.methods.myFunction().call().then(console.log); but methids methods I get the error then I get the error that the function is undefined. The code below doesn't ...
0
votes
1answer
781 views

Unlock remote account

I have smart contract deployed that accepts funds (via fallback function function() payable { ... }). Also I have frontend using web3 to send funds. When I tested it with local node (and JSON wallets ...
0
votes
1answer
116 views

Problem with meteor server side call to Ethereum node

I try to interact with Ethereum node via web3 lib. (meteor add ethereum:web3) Meteor 1.5.4.1 lib.js if (typeof web3 === ‘undefined’){ web3 = new Web3(new Web3.providers.HttpProvider(‘http://127.0.0....
0
votes
1answer
2k views

Invalid JSON RPC response: undefined

I'm trying to create an account through Node.js. This is my code: export async function createNewAccount() { var web3Instance = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));...
0
votes
1answer
235 views

How Do You Parse Web3 Retuned JSON Objects of Events?

I am using Web3 1.0 to listen to events from a contract like this: tokenContract.events.AddressList({ fromBlock: 6020474, toBlock: 'latest' }, (error, events) => { ...
0
votes
2answers
781 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 ...
0
votes
1answer
307 views

Cannot sign a message with web3js (invalid from address)

So I am trying to create a signature of a string, but I cannot do that, as I always get error stating MetaMask - RPC Error: Error: WalletMiddleware - Invalid "from" address. (code: -32603). I am ...
0
votes
1answer
467 views

“instance.at(addr) is not a function” in truffle console (access to non-migrated contracts)

I have a setup with one contract that is a singleton and is migrated to e.g. a testnet through the truffle console. This contract "creates" new contracts, which I want to access in the truffle console....
0
votes
1answer
1k views

Web3 sendSignedTransaction Transaction cost

I'm new to Ethereum world. I've just manage to create an example that calculates transaction fee and sends a signed transaction without a contract using Web3js library. My issue is that my test ...
0
votes
2answers
337 views

Do I have to run geth locally to access Rinkeby via web3.js?

I have used truffle to a migrate some contracts to a local instance of geth that points at Rinkeby. The problem is that I'm behind a firewall, with little hope of getting port 8545 open, so now I can'...
0
votes
2answers
788 views

using abi generated by truffle in DApp

I use truffle to deploy contract to ganache network. I like to use the json file generated by the truffle in the DApp rather writing messy ABI into it. I tried the below piece of code and it gives ...
0
votes
2answers
671 views

web3 detect/listen to events if someone send ether to addresses

I need to constantly keep running some code to detect if someone has in the past minute sent some ether/token to a lot of addresses, is there better way to do than https://ethereum.stackexchange.com/a/...
0
votes
2answers
249 views

Gas issue on sendRawTransaction on the rinkeby network

I'm facing a gas issue on rinkeby network on sendRawTransaction. Tested with various gas value to experiment and getting either insufficient funds for gas * price + value or exceeds block gas limit. ...
0
votes
1answer
133 views

How does Ethereum Smart Contract work on Mobile Client

I want to deploy a smart contract on server and interact with it using mobile client. I'm not familiar with how does that work but after some research, I found something like below: If we compare ...
0
votes
2answers
3k views

Cannot read property 'deployed' of undefined issue

I am trying to launch an Election-Dapp. I have these dependencies installed: - Nodejs v9.11.1 - npm v5.8.0 - Truffle v4.1.3 - web3js v0.2 - ganache-cli Below is my solidity contract pragma ...
0
votes
2answers
1k views

Error: Invalid JSON RPC response: “” using infura

My code: const contract = require('truffle-contract'); const fs = require('fs'); const HDWalletProvider = require('truffle-hdwallet-provider'); const Web3 = require('web3'); const fileContents = fs....
0
votes
1answer
161 views

In node.js event is not fired

I am using web socket to get event. sending transaction works fine. but event is not fired. also I referred Web3 events not working but it does not work, too. I used eventemitter also. but it did ...
0
votes
2answers
776 views

truffle/web3 event listeners returns nothing

We have an event being triggered in a contract and our listeners on the client cant receive the return value. https://gist.github.com/stupeters187/9529b54fe0d48ee606ad06ced6b16031 Update: metamask ...
0
votes
2answers
58 views

I'm trying to create an app that allows people to exchange ether between themselves but I have the error: “web3.eth.transact is not a function”

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <center> <title>dEnergy</title> </head> <body> <label for="name" ...
0
votes
0answers
1k views

passing address as a function parameter in web3

I've this contract that gets 'address' type variable as input parameter to function and sets it to a variable. This works fine in Remix. I'm trying to call this using web3js and am getting an Uncaught ...
0
votes
3answers
2k views

calling smart contract functions from app.js

I deployed a smart contract to ganache network using truffle from account1. The code of smart contract is as follows. pragma solidity ^0.4.0; import "./strings.sol"; import "./safemath.sol"; ...
0
votes
1answer
559 views

Cannot connect to testrpc

I have a testrpc running on a virtual machine (Ubuntu 16.04) and it works properly when I interact with it using the truffle console. My only goal is to call a smart contract that simply sends ether ...
0
votes
1answer
171 views

truffle-contract: cannot test method before real consume ether method

I am using truffle-contract for connecting between frontend and smart contract. Currently, I can call method on smart contract and can consume ether successfully. const result = await instance....

1
6 7 8
9
10