How can I convert my uint8[] to uint[] in Solidity? I have a function that expects uint[], but my array has type uint8[].


Since you cannot only implicitly or explicitly convert from uint8[] to uint256[], you would have to do something like this:

contract array {

function conversion (uint8[] array8) returns(uint[] array256) {
   for (uint i = 0 ; i < array8.length ; i++ ) {
       array256[i] = array8[i];


   return array256;


Maybe something like this?

contract X {
    uint8[] public arr8 = [3,4,5];
    uint256[] public arr256;

    function myFunc(uint[] _arr256) public {
        arr256 = _arr256;

    function proxyFunc(uint8[] _arr8) public {
        uint[] memory _arr256 = new uint[](_arr8.length);
        for (uint i = 0; i < _arr8.length; i++) {
            _arr256[i] = uint256(_arr8[i]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.