Questions tagged [type-casting]

Type casting is the act of converting a value from one data type to another in a computer program.

Filter by
Sorted by
Tagged with
0
votes
1answer
29 views

Solidity, how to cast SmartContract type to address

I am currently a bit stuck with my contract, the issue is following: I define a smartcontract type which is used for another address (aka address is smartcontract that provides the specified interface)...
0
votes
1answer
298 views

A solidity 0.5.x function to convert adress-string to ethereum address

I'm looking for a Solidity 0.5.x compatible function to convert a string with and address like "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe" into a real address. I did use this function: function ...
0
votes
1answer
127 views

Cast contract to address payable

I am wondering if it is possible to cast a contract-reference to an address payable (in order to send to it money) or if it is possible to declare a contract-reference directly payable (with solidity >...
1
vote
1answer
322 views

How to convert bytes32 to uint8 in solidity ^0.5.0?

I can see that conversions from bytes to uint used to be much easier in previous versions of solidity. Now, using the same syntax, I get this error: TypeError: Explicit type conversion not allowed ...
9
votes
2answers
3k views

What's the difference between 'address' and 'address payable'?

I saw a Solidity smart contract where some variables were declared with the type address and some were declared with the type address payable. What are the differences between the two? Do they store ...
1
vote
0answers
57 views

on the implicit type conversion rules in Solidity

Question in one sentence: Are there seperate implicit type conversion rules for function call resolution (other than the conversion rules for the remaining cases)? Regarding the array type ...
0
votes
2answers
364 views

abi.encodePacked with lot of zeros

According this documentation types shorter than 32 bytes are neither zero padded nor sign extended and When I use abi.encodePacked(address, uint, uint, address) I am getting a result with lot of ...
3
votes
1answer
47 views

The most gas-efficient way to convert msg.data to int128?

Is there any more gas-efficient way to convert msg.data to int128? Here is some suggested impl: function bytesToBytes16(bytes b, uint offset) private pure returns (bytes16) { bytes16 out; for (...
1
vote
1answer
28 views

Is there a need to check for null after casting?

Example: MyReceiver my = MyReceiver(_to); // To is an arbitrary address user provided my.someFunction(); // Do I need to check for my == null before calling? Strange enough I do ...
0
votes
1answer
338 views

Going from uint256 to uint8, is it possible?

I have a function that creates random numbers with a maximum value that you gives to it, the function was made to work with any uint256, and using % operator it returns a value between 0 and the ...
0
votes
1answer
518 views

How to typecast keccak256 function with multiple arguments to uint256?

solidity ^0.4.19 (works) uint256 randNonce++; return uint256(keccak256(msg.sender, randNonce, now)) solidity ^0.4.24 (throws) uint256 randNonce++; return uint256(keccak256(abi.encodePacked(msg....
1
vote
2answers
163 views

How to type-cast a function pointer in Solidity?

I have a function that takes a parameter of type function (uint256) view returns (uint256). I want to pass it a pointer to a function of type function (uint256) pure returns (uint256). Obviously ...