14
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 ...
11
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 ...
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 ...
9
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 ...
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 ...
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
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 ...
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
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
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 ...
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 ...
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
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
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-...
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)
3
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
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
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";...
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 truffle@4.1.15
3
votes
"before all" hook: prepare suite
npm uninstall -g truffle
npm install -g truffle@5.1.10 (always got me back on track)
3
votes
ReferenceError: address is not defined
You have two problems:
web3.eth.getBalance() returns an promiEvent object, to obtain the expected value you need to await for it
Javascript doesn't support large numbers, so values are wrapped in BN ...
3
votes
Accepted
Solidity Invalid implicit conversion from string memory to bytes memory requested
Argument to sha256 should be in bytes. But you're passing document which is a string. Following would work.
function proofFor(bytes memory document) public pure returns(bytes32) {
return sha256(...
3
votes
Solidity Invalid implicit conversion from string memory to bytes memory requested
Should probably be
return sha256(bytes (document));
3
votes
Solidity Compatibility Configuration
Maybe it will be easier for you to start with http://remix.ethereum.org and move to ganache after you gather some experience (or just stay in remix).
The main problem here is that you will need ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
error × 358solidity × 150
remix × 62
web3js × 38
contract-development × 31
truffle × 29
metamask × 20
transactions × 19
gas × 18
tokens × 16
erc-20 × 13
etherscan × 13
contract-debugging × 13
blockchain × 12
compiler × 11
brownie × 11
contract-deployment × 10
javascript × 10
parser × 10
contract-design × 9
ether × 9
go-ethereum × 8
python × 8
web3.py × 7
truffle-migration × 7