Hot answers tagged

10

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 a transaction, the node that receives it first may not be the same node that handles the next transaction, or that handles the eth_getTransactionCount call ...


10

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 truffle npm install -g truffle


6

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('bluebird'); const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider(<WEB3_PROVIDER_URL>)); if (typeof web3.eth.getAccountsPromise ...


6

To initialize an empty array instead of in solidity 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 splitN(uint256 n) constant returns (uint8[12]) { uint8[12] memory traits; // alter values in traits ... return traits; }


5

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 the array as follows: function getTraits() constant returns (uint8[3]){ uint8[3] memory traits = [1,2,3]; return traits; }


5

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 (solc-js) You can try to update solc manually and the issue will be fixed. $ cd /usr/local/lib/node_modules/truffle $ npm install solc@0.4.21 this will ...


4

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 you longer than the remaining lifetime of the universe. Alternatively, lobby the Ethereum community to create a hard fork of the blockchain just for you, in ...


3

Maintainer of ganache here. This is a known bug in the beta. See https://github.com/trufflesuite/ganache-cli/issues/471


3

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 a rogue LOCK that caused this issue - I'm not sure why, possibly the normal shutdown of the previous geth session was distured. Remove the Lockfile Debian/...


3

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 instead continue execution. If this is the function directly being called in the transaction, then the only difference is whether the transaction completes ...


3

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 ownerInfo() public view returns (string)


3

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. Another thing is that in your send function you have: msg.sender.transfer(msg.value); but should be _receiver.transfer(msg.value); Also, is not clear what ...


3

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 adopters array. You should ideally have a getAdopters(uint256 id) function that returns just one adopter.


3

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 swing at guessing why you're getting this error though, I would assume that you're quotes around localhost are smart quotes, and not the standard kind (they show ...


3

Here is how to cast address to address payable: address addr = 0x****; address payable wallet = address(uint160(addr)); And contract cast to address payable (thx to @Cyril): MyContract addr = MyContract(0x****); address payable wallet = address(uint160(address(addr)));


3

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

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

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 openzeppelin-solidity@1.5.0 not openzeppelin-solidity@2.0.0 Then in Remix make sure to select v0.4.18 as your compiler


3

Try with this: pragma solidity ^0.5.1; contract MKotET1_12{ address payable king; uint public claimPrice = 100; function calculateCompensation() public returns(uint) {} function() external payable { if (msg.value < claimPrice) revert(); uint compensation = calculateCompensation(); (bool success, ) = king....


3

This seems to be a remix bug. When you deploy it using web3 or so it should work properly. Everything should be fine. As the other answer stated you can bypass this problem.


2

Error reason strings for revert and require has been introduced in solidity 0.4.22. You can define the reason of revert and require. With some bug fixes, latest version of solidity is 0.4.23. For more details: https://medium.com/secureblocks/solidity-0-4-22-enhancements-94d2b9b8b6fe


2

Ethereum only uses integer arithmetic and will truncate mathematical operations. The expression, will calculate 5/100 first which is 0. winningBid.amount * (5/100) = winningBid.amount * 0 = 0 The solution is to force the order of the operations to first multiply require(_amount > winningBid.amount + (winningBid.amount * 5) / 100); Also it is ...


2

Start geth in Terminal first: > geth --mine Launch Mist, but also from Terminal so you can pass commands to make it connect to the IPC created by geth. On my computer, it looks something like this and try > /Applications/Mist.app/Contents/MacOS/Mist --rpc ~/Library/Ethereum/geth.ipc Note: you need to change the paths above to correspond with where ...


2

I've got this error: But you don't have any errors. You have two warnings. One is about the potentially unbounded gas usage of approveAndCall. The compiler has no idea how much gas will be consumed because that depends on what contract tokenRecipient is going to be called on. There's nothing wrong with getting a gas estimate like this; it just means that ...


2

As suggested by Ismael in the comments above, my mistake was that MetaMask did two transactions. So the first one was an approval that was missing.


2

I have figured it out at my end while facing the same problem. When you are using fromBlock and toBlock parameters in the function call web3.eth.getPastLogs you will have to cast the values to their hex version/equivalent. Which can be done using : web3.utils.toHex(<fromBlock/toBlock_Value>) This worked for me.


2

You problem is caused by this lines necessaryBalance += getPayoutForType(betType) * msg.value; if (necessaryBalance > this.balance) throw; At the beginning this.balance is zero. When you call betSingle for the first time msg.value will be equal to this.balance. Now getPayoutForType(betType) will return 35. And then necessaryBalance = 35 * msg....


2

It has failed and any changes to the blockchain are reverted. Hence the receiver will not receive your ERC20 tokens. Your gas limit is too low. Increase your gas limit.


2

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 seems to work on testnet (ropsten, rinkeby) and not work on mainnet. It fails especially miserably when performing transactions outside of the standard deployer....


2

In case it isn't clear. pragma "In computer programming, a directive or pragma (from "pragmatic") is a language construct that specifies how a compiler (or other translator) should process its input." - https://en.wikipedia.org/wiki/Directive_(programming) It's just saying it was designed for a compiler of version 0.4.0 or better (^). The solc compiler ...


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