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');
...
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 ...
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 ...
4
votes
Ethers.js equivalent for web3.eth.getStorageAt?
In Ethers V6 it's now getStorage
await provider.getStorage(address, slot);
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, ...
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
...
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 ...
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 ...
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 ...
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 (...
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 ...
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 ...
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,
'...
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 ...
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, ...
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:...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
web3js × 6086solidity × 1688
go-ethereum × 758
metamask × 632
javascript × 512
truffle × 479
nodejs × 411
blockchain × 373
transactions × 364
contract-development × 349
ethereumjs × 274
ethers.js × 266
events × 253
dapps × 249
react × 222
remix × 196
ether × 196
contract-deployment × 194
erc-20 × 192
contract-invocation × 185
infura × 183
web3-providers × 173
web3.py × 161
dapp-development × 160
tokens × 151