Questions tagged [web3js]

Use this tag with questions about programming for the Ethereum JavaScript API.

Web3.js is open source and continuously updated since 2015. It has everything you need to start interacting with the Ethereum blockchain, giving easy access to accounts, events, smart contracts.

Useful links

2372 questions
0
votes
1 answer

Transaction problem with Web3 BEP20 in Node JS

So I'm trying to send a transaction on BSC (testnet) with nodejs web3 (bep-20). After sending via the contract with web3 I only get a TX hash as a response and no receipt or anything like that. When I search for the transaction on the blockchain it…
0
votes
1 answer

How to interact a front End with smart contracts and blockchain in mobile Dapps?

i want to build a mobile DeFi wallet but i'm wondering how to interact my front End with smart contracts and the ethereum blockchain. Please help me. Will i use truffle in it like other web Dapps ?
0
votes
1 answer

Calling a smart contract function using truffle/hdwallet-provider

I have a contract on polygon and I want to call a write function setPrice(uint256 _price) but when I run this code then I am getting an error: { code: -32000, message: 'transaction underpriced' } Smart Contract:…
0
votes
1 answer

How to decode the indexed string param in an event using web3.js?

This is the event - event BridgeAdded( string indexed tokenTicker, string tokenName, string imageUrl ); I use web3.eth.abi.decodeParameter("string", topics[1]) to decode the indexed string param but get this error…
0
votes
1 answer

Using events to read solidity struct

My smart contract has a struct and a function that populates it: struct voter { uint ID; string firstName; string lastName; uint phone; string addy; //add picture } contract Poll { uint public numVoters; …
Saif Zaabi
  • 11
  • 1
0
votes
2 answers

Get the price of tokens with web3js

I wanted to know if it was possible to get the price of tokens with web3.js For example I would like to get the price of WBTC on Uniswap and on SushiSwap If you have any documentation or tutorials I'm interested Thanks in advance
0
votes
1 answer

Creating a transaction message for eth_sign

I don't know how to create a transaction message for the method eth_sign (to, msg). I know that through eth_sign you can send a request for a transaction signature (in metamask for example), which will be passed in the msg parameter, which will be…
Galaxy773
  • 11
  • 1
  • 5
0
votes
1 answer

How to simulate block minting in smart contracts unit test?

I am writing a smart contract for staking. Earnings are increased each time a new block is minted. In order to test the calculation of earnings, I need to simulate a certain number of blocks to be minted in my test suite. Is there a function in…
Yves Toiser
  • 26
  • 2
  • 6
0
votes
1 answer

How to call solidity view function in react js

I have developed a smart contract and in that I have used mapping that stores the txn hash with respect to the tokenID as key. Now I want to retrieve the data from mapping through a function as shown below: How do I call this function in reactJS.…
Zoha Akram
  • 47
  • 9
0
votes
1 answer

How to get chain ID from MetaMask using JavaScript async await

How to get result value out of async await function? I am trying to get current chain ID in the MetaMask, I get object in return of the function. I am expecting 0x4, but it is not accessible outside of the function. let account; let…
Majoris
  • 2,963
  • 6
  • 47
  • 81
0
votes
1 answer

web3js baseFeePerGas 0x7 not number

I want baseFeePerGas to be Number but i get 0x7 here is the code const ethers = require('ethers'); function getBlock() { const block = window.web3.eth.getBlock('latest'); return block .then(data => { …
0
votes
1 answer

i am trying to send a transaction but it throws an error

eror on terminal if (!cond) throw new Error(msg) ^ Error: Expected private key to be an Uint8Array with length 32 my Code its about signing eror. I am absolutely lost as to why this is not working as I have copied every piece of code…
rayan
  • 11
  • 1
0
votes
1 answer

Does web3js have a similar override option as web3py?

I was reading about state override in this article, where you can essentially alter the code of a called contract to do what your own, locally written contract dictates. No deploys occur, and no writes to the blockchain are possible, but it ends up…
user2497586
0
votes
1 answer

React onclick function running automatically wihout clicking

My Problem is: I have react code that communicates with a smart contract. When i start the server the oncklick function openLong() runs automatically(multiple times-> 3 transactions in Metamask) before i even click the button and when i click the…
blossom
  • 15
  • 3
0
votes
1 answer

buy and sell in one transaction in Web3, to check for honeypots

How can i turn this buy function into a transaction that buys and sell in a single transaction? The reason behind this is to check if a token is a honeypot and will not allow me sell the token, but i dont know how to go on from here. Maybe there is…
Soma Juice
  • 369
  • 1
  • 11