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 ...
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 ...
12
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 ...
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 ...
8
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 ...
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 ...
8
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 ...
7
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 ...
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('...
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 ...
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 ...
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 (...
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-...
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 ...
5
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/...
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
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 ...
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 ...
4
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";...
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/...
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)
4
votes
Solidity Invalid implicit conversion from string memory to bytes memory requested
Should probably be
return sha256(bytes (document));
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);
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,...
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 ...
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
...
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.
...
3
votes
Expected primary expression error
Your syntax error can easily be fixed by just changing &,& to &&.
However, this will then give you a call stack size error, since you cannot return an object as large as your ...
3
votes
Accepted
Fatal: Error starting protocol stack: listen tcp: lookup ”localhost”: no such host
While I can't answer why you're getting this specific error, what I can tell you is that specifying --rcpaddr localhost is unnecessary as localhost is the default rpcaddr value.
If I were to take a ...
3
votes
Truffle Box at URL https://github.com/truffle-box/bare-box.git doesn't exist
I had the same issue when my truffle version was 4.1.14.
When I upgraded to version 4.1.15 the issue was solved. I just had to run npm i -g [email protected]
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
error × 445solidity × 199
remix × 78
web3js × 43
contract-development × 35
truffle × 29
transactions × 22
metamask × 21
contract-deployment × 19
gas × 19
javascript × 17
hardhat × 17
tokens × 16
erc-20 × 16
etherscan × 15
ether × 13
contract-debugging × 13
brownie × 13
go-ethereum × 12
compiler × 12
blockchain × 11
testing × 10
contract-design × 9
web3.py × 9
nft × 9