Hot answers tagged

15 votes

TypeError: Web3 is not a constructor when trying to use node.js with truffle-contract

I was stuck with the same error while trying to use this in nodejs.. I finally found the fix. Apparently, in Web3.js 4.x, we're supposed to import it like this: const { Web3 } = require('web3'); ...
Siddharth Maurya's user avatar
5 votes

How do I decode the transaction's log with Web3.py?

I was struggling with same issue. When you are subscribed to contract's topic log, aditional searching for data using transaction hash is adding latency to processing. I have written this class for ...
Peter Trcka's user avatar
5 votes
Accepted

What is the use of Truffle/Hardhat?

I had used both Truffle, Brownie && Hardhat for SmartContract development. All of them are good, and they serve their purpose. The reason you need these tools comes down to the fact that ...
Sky's user avatar
  • 2,204
4 votes

Ethers.js equivalent for web3.eth.getStorageAt?

In Ethers V6 it's now getStorage await provider.getStorage(address, slot);
callmemath's user avatar
4 votes

I was trying to convert private key of an account to its public key but getting an error

Well, obviously it doesn't like your private key format. I'm unsure what style private keys the function accepts. A typical private key is, for example, ...
Lauri Peltonen's user avatar
3 votes

What happens when you connect wallet to website?

Just adding a bit more caution to the accepted answer: As per Metamask, connecting your wallet allows the following: | See address, account balance, activity and suggest transactions to approve ...
Janac Meena's user avatar
3 votes
Accepted

Ethernaut Level 24 - Puzzle Wallet

Contract inheritance: UpgradeableProxy is just a template with some functions, constants and variables so PuzzleProxy can reuse. Yes you can reuse the logic written in parent contracts, some functions ...
minhhn2910's user avatar
  • 1,690
3 votes
Accepted

Truffle vs Hardhat vs Foundry and web3js vs ethersjs

For me it's just foundry. You have the telegram chat for support with the developers of it, it's faster than all the competitors and you can write your own tests/scripts with solidity itself. This ...
Josep Bové's user avatar
3 votes
Accepted

Get all liquidity in all dex of a token

You have to use the factory abi of all dexes to get liquidity for the mostly used tokens from front end. Eg. the factory address of pancakeswap is 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73. The abi ...
Safi's user avatar
  • 848
3 votes

Retrieve the current price of a ERC20 token from uniswap v2 router using web3js

Thanks to @kfx! Indeed, to find out the price of a token with slippage using the getAmountsOut method, you must specify the amount in the token's decimals as the first value. The web3js conversion (...
Ivan's user avatar
  • 129
3 votes

Is it good for me to switch to Moralis from web3js?

Ether js and web3 js are the de facto to be used in web3 to interact with the blockchain. Moralis is a third party service which is, obviously, a paid service. In the world of blockchain and ...
Safi's user avatar
  • 848
3 votes

Is it good for me to switch to Moralis from web3js?

Moralis is not equal to Ethers or Web3.js. It is not apples to apple comparison. Moralis is a commercial Web3 Data, Streams, and Authentication API. It has recently transitioned to be utilized as a ...
PSS's user avatar
  • 529
3 votes
Accepted

Web3Py 'TRANSFER_FROM_FAILED' error when executing a swap even if tokens spending have been approved

You are getting an error because you approve the wrong address to spend tokens. tx = usdc_contract.functions.approve(account_address, 1000000).buildTransaction({ 'from': account_address, '...
Adam Boudj's user avatar
  • 2,331
2 votes

How to read all token balances from wallet?

You can now use Amazon Managed Blockchain Query to easily retrieve a full list of token balances for a given EOA at finality (2 epochs on Ethereum) or from history (based on a timestamp). I've ...
Forrest's user avatar
  • 21
2 votes

How do I decode the transaction's log with Web3.py?

The above solutions are excellent, but only work on legacy transactions. To decode any type of transaction (legacy, EIP1559, EIP2930, etc) please rely on the py-evm package. Here's a working example, ...
coccoinomane's user avatar
2 votes

Decode input data on transaction

I have developed a simple ruby gem for decoding and encoding transactions input data in EVM based blockchains: https://github.com/rkotov93/evm-tx-input-decoder Here's usage example regarding your case:...
rkotov93's user avatar
2 votes

How to get a index position of the storage on the smart contract?

If you are using foundry for development, the cast command line utility will give you entire storage layout for your contract. You'll have to give an rpc-url for the network and the blockscanner api ...
Siddharth Bhoite's user avatar
2 votes

How to sign transaction using web3.js via metamask

Yes, it is possible to sign transactions in the browser and send them to your backend server. The web3.js library provides a method called eth_signTransaction which will allow you to sign the ...
Cryptoineer's user avatar
2 votes
Accepted

Truffle test is failing with "the tx doesn't have the correct nonce" error

As a suggestion, you should have said that you were taking the "6 Figure Blockchain Developer" course from Eat The Blocks. By the way, I'm taking that course and I ran into the same issue ...
Hector V's user avatar
2 votes

What is the use of Truffle/Hardhat?

Assuming the last line of your question is "when we can't actually build anything such as a Dapp" So, in Blockchain development, testing on real environments can be costly. Since you ...
Ishan's user avatar
  • 51
2 votes

How do you change an integer to a hex in javascript / web3.js?

To convert an integer to a hexadecimal value in JavaScript, you can use the Number.toString() method and specify a radix of 16 (hexadecimal) as the second argument. For example, to convert the integer ...
david fnck's user avatar
2 votes
Accepted

How to read a transaction in human readable format using web3?

it's not difficult. try this. To convert the gas and value fields from a hash to Gwei or Ether, you can use the web3.utils.fromWei() method provided by the Web3 library. This method takes the value in ...
david fnck's user avatar
2 votes

Send both erc20 and native ether to contract on deployment

Seems you already know how to send ethers to the contract and to send some erc20 as well during deployment, you can modify the constructor to transfer the link tokens while deployment. The code would ...
Shubham Kumar's user avatar
2 votes
Accepted

EtherJS: Why the wallet address created from etheres.Wallet.createRandom() is exact same on different chains like Ethereum, BSC, Polygon and etc

With the same private key you will always get the same address in BSC, Polygon, ETH because they use the same address encoding scheme. In particular it's the last 20 bytes of the Keccak-256 hash of ...
minhhn2910's user avatar
  • 1,690
2 votes
Accepted

How to encrypt "InputData" to use my smart contract to make it unreadable

To obfuscate the input so that etherscan cannot decode it : YES. To hide your contract's activity (ERC20 transfer): NO. Although you can obfuscate and hide your input data, people can see your ...
minhhn2910's user avatar
  • 1,690
2 votes

If substituting web3.js for MetaMask, does it also track users' IP address?

dev advocate at Chainstack here! To answer this question: Question: If you substitute MetaMask with web3.js to carry out all the same functions for your wallet, does web3.js, or the UI clients for ...
Dave Dev Advocate Chainstack's user avatar
2 votes
Accepted

Get the entire contents of an ethereum block with the fewest queries?

Hi Developer advocate from Chainstack here Please give this a try: web3.eth.getBlock(blockNumber,true) This returns all transaction details with getBlock method. JSFiddle example Wuzhong/Chainstack
Wuzhong - Chainstack DevEx's user avatar
2 votes
Accepted

Where are the transactions in the genesis block?

The genesis block had no transactions, exactly like what you have queried on the eth node. On Etherscan, 8,893 "transactions" are actually the 8893 accounts involved in ETH ICO Presale ...
minhhn2910's user avatar
  • 1,690
2 votes

Can I make a Dapp in react that doesn't uses metamask at all?

this is awesome to onboard new users into web3. You can use Gelato Relay https://docs.gelato.network/developer-services/relay which allows you to send transactions via a normal HTTP post to the ...
donoso.eth's user avatar
  • 1,383
2 votes

Does delegatecall also works for calling other contract's constructor?

Since the constructor is only once used when you deploy a smart contract there is no way to use delegatecall for it. If you can explain why you want to do something like this maybe I can help with ...
Catalin's user avatar
  • 389

Only top scored, non community-wiki answers of a minimum length are eligible