Skip to main content
16 votes

Explicit type conversion not allowed from "bytes1" to "uint256"

The shortest solution I discovered after several tries: uint length = uint(uint8(arr[i]));
k06a's user avatar
  • 3,036
9 votes
Accepted

Data location can only be specified for array, struct or mapping types, but "memory" was given

Change this: uint256 memory _val To this: uint256 _val Because uint256 is neither array, nor struct nor mapping nor string.
goodvibration's user avatar
8 votes
Accepted

How to get access to the storage mapping through the solidity assembler?

Solution function getStorageValue(uint num, uint slot) public view returns (address result) { assembly { // Store num in memory scratch space (note: lookup "free memory pointer" if you ...
sea212's user avatar
  • 1,840
7 votes
Accepted

What is the logic by which tokens are ordered when creating a new Uniswap V2 pair?

It's easy to see what that comparison does with a hands-on approach on Remix: pragma solidity =0.5.16; contract AddressComparison { function cmp(address token0, address token1) external pure ...
Paul Razvan Berg's user avatar
6 votes

Avoid using "now"

The use of block.timestamp (which is what now is an alias of) is often discouraged because it is somewhat manipulable by miners. This is only an issue if you need the time to be precise to within ~90 ...
Tjaden Hess's user avatar
  • 37.1k
5 votes
Accepted

Explicit type conversion not allowed from "bytes32" to "address"

address uniqueId = address(bytes20(sha256(abi.encodePacked(msg.sender,'block.timestamp')))); Also, why 'block.timestamp' is in quotes? Maybe it should be: address uniqueId = address(bytes20(sha256(...
Mikhail Vladimirov's user avatar
4 votes
Accepted

How to test kill function including selfdestruct()?

I don't quite get the code. It looks it should be xtn.kill(); In any case, kill wipes out the state and the bytecode. If I'm not mistaken, the return step will never happen because the contract was ...
Rob Hitchens's user avatar
  • 55.4k
4 votes
Accepted

Why solidity's keccak returns different value from online generators?

It seems like you treated "315f6b6f74000000000000000000000000000000000000000000000000000000" like a string instead of the hexadecimal byte sequence it actually is. Via web3 0.2.x: web3.sha3('...
user19510's user avatar
  • 28.1k
4 votes

How to get require() error message?

Yes you can! I made an NPM package to help with this: eth-revert-reason. You can use that package to get the revert reason from a transaction with just the hash! It is hard to decode the revert ...
Shane Fontaine's user avatar
3 votes

Avoid using "now"

The community likes to use exact things like "block numbers" which cannot be tampered with by the miners. The now / block.timestamp can be manipulated by the miner to a certain degree as it relies ...
Micky Socaci's user avatar
  • 1,312
3 votes
Accepted

Using address.call.value to send ether from contract to contract in 0.5.0 and above

From https://solidity.readthedocs.io/en/v0.5.7/050-breaking-changes.html#semantic-and-syntactic-changes: Functions .call(), .delegatecall() and .staticcall() now return (bool, bytes memory) to ...
user19510's user avatar
  • 28.1k
3 votes
Accepted

How does the named return variables in solidity work

Your interpretation is correct. That function always returns false.
user19510's user avatar
  • 28.1k
3 votes

How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

As mentioned in comments Solidity doesn't have such functionality. Solidity (and also EVM) doesn't understand anything about address checksums, it's only a construct added on top of the toolkits. If ...
Lauri Peltonen's user avatar
3 votes

How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

We can get help from the solidity compiler since it's showing the fixed checksummed address in below compiler error SyntaxError: This looks like an address but has an invalid checksum. Correct ...
noelyahan's user avatar
  • 131
3 votes

How to type cast fixed size byte arrays in solc 0.5.x?

I figured it out... You have to cast the uint to the same length so in this case it would be: bytes28 bar = bytes28(uint224(foo)); If it were bytes16 it would be: bytes16 bar = bytes28(uint128(foo))...
okwme's user avatar
  • 293
3 votes

Is it true that we can't make multiple Transfer() to the same address within a single transaction now?

Solidity arrays are zero-based. If you run this code with two addresses, it will only run once, since you initialize i with 1. This means that the for-loop will stop after one iteration (assuming ...
Morten's user avatar
  • 6,027
3 votes

Error HH411: The library openzeppelin-solidity is not installed. Try installing it using npm (for old 0.5.0 solidity code)

Thanks to @zmy comment, pointing to https://www.npmjs.com/package/openzeppelin-solidity. 2.3.0 is earliest version on npm registry as "@openzeppelin/contracts" https://www.npmjs.com/package/@...
Paul Verest's user avatar
2 votes

Truffle console error "Error: Returned error: VM Exception while processing transaction: revert"

The problem is with transferFrom, it is declared as external in ERC20. When you execute sendTxAndMessage transferFrom(_from, _to, _value); It is equivalent to an external call ERC20(...
Ismael's user avatar
  • 30.5k
2 votes

Solidity Vs Vyper

From a top-level, the biggest difference is the fact that Vyper is focused on security and doing its best to protect developers' code from being exploited. It has the advantage of having seen Solidity ...
Shane Fontaine's user avatar
2 votes
Accepted

Solidity 0.5.2 - OpenZeppelin - New SafeERC20 callOptionalReturn(token,data)

If I'm not mistaken, the issue is token.transfer.selector is trying to work out the signature from the source code. It would be equivalent to abi.encodeWithSelector(bytes4(keccak256(bytes(signature))...
Rob Hitchens's user avatar
  • 55.4k
2 votes

Update Solidity - 0.5.4 (ERC20 + ERC677)

Ended up with an ERC223 implementation :) Thanks ! pragma solidity ^0.5.2; /** * @title SafeMath * @dev Unsigned math operations with safety checks that revert on error. */ library SafeMath { ...
Liberalite's user avatar
2 votes
Accepted

Create Contract Solidity 0.5

In Solidity 0.5, you need to explicitly store the type of the contract being created (as opposed to simply using the address type). Use the following code to achieve your goals: Contract 1: uint ...
Shane Fontaine's user avatar
2 votes
Accepted

Will ERC223 Tokens work after Serenity Update?

In current understanding, Serenity will be a separate blockchain, so no contracts will automatically migrate from current Ethereum to Serenity. New token contracts deployed on Serenity will probably ...
Mikhail Vladimirov's user avatar
2 votes

transferFrom function not working in ICO Smart contract

I found that the generated tokens are with the address which deployed it Token contracts typically assign the total supply to the contract deployer, so this is normal. A token contract is a ledger, ...
Rob Hitchens's user avatar
  • 55.4k
2 votes

transferFrom function not working in ICO Smart contract

The transferFrom is failing, I suppose, because of the require(_value <= allowed[_from][msg.sender]); Did you first approve the msg.sender to transfer tokens from _from address? In the cases like ...
biplavo's user avatar
  • 934
2 votes
Accepted

openzeppelin mint sequence

I got the answer myself. It's because solidity uses c3 linearlization. Another simplifying way to explain this is that when a function is called that is defined multiple times in different ...
bbusdriver's user avatar
  • 1,154
2 votes
Accepted

How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

The simple answer is that in solidity: address(0xa54D3c09E34aC96807c1CC397404bF2B98DC4eFb); It is true that the compiler warns you of incorrect checksum when it sees one, but that warning is ...
goodvibration's user avatar
2 votes

How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

Other colleagues did underline very well the point: in Solidity does not exist something called “address with correct checksum”. There exist addresses. Full stop. The request for a proper checksum ...
Rick Park's user avatar
  • 3,194
2 votes

How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

The solution is simple... https://solidity.readthedocs.io/en/develop/types.html#address-literals Hexadecimal literals that pass the address checksum test, for example ...
Damir Olejar's user avatar
2 votes
Accepted

What is the unit for the tx.gasprice?

The unit is wei. Wei is the lowest possible denomination that can be handled by Solidity. Because of this, various values can be calculated (but not necessarily the other way around), such as ether, ...
Shane Fontaine's user avatar

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