Skip to main content
Share Your Experience: Take the 2024 Developer Survey
15 votes
Accepted

Solidity initialize memory array of fixed size

To initialize an empty array instead of uint8[12] memory traits = new uint8[12]; use uint8[12] memory traits;. Then you can alter the array in the // alter values in traits ... section. function ...
Achala Dissanayake's user avatar
13 votes

Solidity initialize memory array of fixed size

In order to initialize an array from memory you have to do it like this: uint8[] memory theArray = new uint8[](12) Where the 12 inside the parenthesis is the array length. You can also initialize ...
pabloruiz55's user avatar
  • 7,666
13 votes
Accepted

Truffle + Infura on Mainnet: Nonce too low error

If you're using Truffle with Infura directly (which it sounds like you are, although it's unclear why you mention MetaMask), you need to be aware that Infura is running on a server farm. If you submit ...
James_pic's user avatar
  • 1,110
11 votes
Accepted

Truffle Box at URL https://github.com/truffle-box/bare-box.git doesn't exist

I found out on Truffle's Gitter channel that something must have broken in version 4. I upgraded to version 5 and the issue is resolved. How to upgrade (more information here): npm uninstall -g ...
Joel Oduro-Afriyie's user avatar
9 votes
Accepted

assign decimal to a variable in solidity

Right, Solidity only supports integers. Try this instead: uint sales = 100; uint afterCommission = sales * 5 / 100; // 5% If it's a variable amount but a whole number percent: uint ...
user19510's user avatar
  • 28.1k
9 votes
Accepted

Ethers.js - Error: invalid BigNumber string

The problem is that the toString of the number will convert it to a scientific representation which cannot be interpreted by the BigNumber. The cleanest way to get around this is to use BigNumber when ...
Richard's user avatar
  • 4,994
8 votes
Accepted

address payable type - store address and send later using Solidity 0.5.0

UPDATE: Solidity 0.6.x now have explicit conversions to payable: payable(userAddress) And for smart contracts: payable(address(smartContract)) Old answer for Solidity 0.5.x: Here is how to cast ...
k06a's user avatar
  • 3,036
8 votes
Accepted

Payable function error: The called function should be payable if you send value and the value you send should be less than your current balance

"The called function should be payable" is a wild guess of a hint and usually wrong. The contract has reverted for any number of reasons. You will have to use debugging techniques to zero in ...
Rob Hitchens's user avatar
  • 55.3k
6 votes

Web3ProviderEngine does not support synchronous requests while : Running migration: 2_deploy_contracts.js

web3.eth.blockNumber is synchronous. You need to change this to web3.eth.getBlockNumber((err, res) => {}) Alternatively you can restructure this chain with promises: const Promise = require('...
carlolm's user avatar
  • 2,326
6 votes
Accepted

Error starting protocol stack: datadir already used by another process

If you're sure that geth is not already running, check for the presence of a LOCK file in the geth subdirectory of your data directory. Under Ubuntu this will be ~/.ethereum/geth. I have experienced ...
csknk's user avatar
  • 176
6 votes

Solidity Compiler - Error: Identifier already declared

This is because the method and the property have the same name. Since solidity automatically creates a public getter function for every public variable in the contract, you don't need function ...
Hari GTT Psicolabis's user avatar
6 votes
Accepted

directory is not empty: brownie

This is because there is stuff in your directory already. You can either: Force create the directory brownie init --force Which will create the brownie sample directory alongside your existing code/...
Patrick Collins's user avatar
6 votes

Error HH19: Your project is an ESM project (you have "type": "module" set in your package.json) but your Hardhat config file uses the .js extension

Downgrading "chai" from 5.00 to 4.3.7 helped solve the error, i had dependencies that require ES modules and thats why i got the error.
Plair's user avatar
  • 71
5 votes
Accepted

Contracts will not compile using truffle with the "emit" keyword included in front of events

I'm afraid that truffle is still using the old solc compiler, that's why you get that error. Indeed $ truffle version Truffle v4.1.3 (core: 4.1.3) //this is the last truffle version Solidity v0.4.19 (...
qbsp's user avatar
  • 4,367
5 votes
Accepted

Solidity Compiler - Error: Identifier already declared

@Hari GTT Psicolabis' answer is right, but that means that you have to specify the ownerInfo field as public to get the benefit of a public getter. string public ownerInfo = "Contract Owner name XYZ";...
qbsp's user avatar
  • 4,367
5 votes

Running out of gas during a deploy due to a large number of require() statements?

I was made aware of a flag in the Ganache command line client that allows unlimited contract sizes during development. By using this flag, I can now deploy/migrate to Ganache without getting an out-...
Robert Oschler's user avatar
5 votes

NotFoundError: Key not found in database [hn]

I encountered the same error when solving the same Ethernaut level. I'm using Remix IDE. When I changed from deploying with JavaScript VM to deploying with Injected Web3 (there's a dropdown menu in ...
SmilingHeretic's user avatar
4 votes
Accepted

New Ganache (1.1.0-beta.0) Causes Invalid JSON RPC response

Maintainer of ganache here. This is a known bug in the beta. See https://github.com/trufflesuite/ganache-cli/issues/471
Ben Burns's user avatar
  • 183
4 votes

What is the advantage of using require instead of return or revert for error handling?

Under the hood, require will revert the transaction, just like revert will. This means that the transaction will fail, and your event will not be logged. return will not stop the transaction and will ...
user19510's user avatar
  • 28.1k
4 votes

Recover Ethereum holding sent to wrong address due to entry error

Simple! You just brute-force as many random private keys as you can until you find the one that corresponds to the address you accidentally sent your Ether to. Only downside, this will probably take ...
AndyK's user avatar
  • 695
4 votes
Accepted

Uncaught ReferenceError: Web3 is not defined Solidity

I hope you are using web3 as browser module. As in their documentation, you can add the CDN link using <script> tags as below, <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/...
Achala Dissanayake's user avatar
4 votes

Invalid bytes32 value

Replace ['Sat', 'Vit'] with: ['Sat', 'Vit'].map(x => web3.fromAscii(x)) if you're on Truffle 4.x (web3 0.x) ['Sat', 'Vit'].map(x => web3.utils.asciiToHex(x)) if you're on Truffle 5.x (web3 1.x)
goodvibration's user avatar
4 votes

Solidity Invalid implicit conversion from string memory to bytes memory requested

Should probably be return sha256(bytes (document));
Mikhail Vladimirov's user avatar
4 votes
Accepted

call: Warning: Unused local variable

You do not need to explicitly state the second variable declaration. You can write it as follows: (bool success, ) = king.call.value(compensation)(""); require(success);
Shane Fontaine's user avatar
4 votes

ParserError: Expected ',' but got identifier

You should not specify the types of parameters when you pass them in a function-call: users[userID] = kullanicilar(string name, string surname, age); Change it to: users[userID] = kullanicilar(name,...
goodvibration's user avatar
4 votes
Accepted

Foundry expectRevert on Custom Error with Multiple Errors

I had to remove the space between uint256 and uint256 on this line: bytes4 selector = bytes4(keccak256("MaximumContributionExceeded(uint256,uint256)"));
currenthandle's user avatar
3 votes

Truffle + Infura on Mainnet: Nonce too low error

Not sure if this is still relevant, but I am going to leave this here for future generations. I've been struggling to deploy with truffle + Infura on mainnet a lot lately. One and the same script ...
George Spasov's user avatar
3 votes
Accepted

Unable to execute web3.eth.accounts[0]

geth --rpc --rpcaddr "localhost" --rpcapi "web3,eth" --rpccorsdomain "*" --rpcvhosts "*" Go(https://github.com/ethereum/wiki/wiki/JSON-RPC#go) You can start the HTTP JSON-RPC with the --rpc flag ...
Ishwar Chandra Tiwari's user avatar
3 votes
Accepted

Smart Contract to send ether

The error is that your contract can not receive ether because it doesn't have a fallback function. Just add this to it: function () public payable{ } This will allows your contract to accept ether. ...
Jaime's user avatar
  • 8,350
3 votes

Expected primary expression error

Your syntax error can easily be fixed by just changing &amp,&amp; to &&. However, this will then give you a call stack size error, since you cannot return an object as large as your ...
Raghav Sood's user avatar
  • 4,050

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