CRYPTO NEWS

DFINITY R&D Team Announces BTC-ICP Integration Beta Release

Ultimately, advanced and sophisticated smart contracts will be available for Bitcoin. The straightforward inclusion of the Web Desktop with the Bitcoin blockchain, which does away with the need for a reliable middleman or overpass, has been made public by the DFINITY R&D team as a beta release. With the integration’s APIs, devs can actually build …

Using array of arrays as a function argument returns "Invalid implicit conversion from uint256 to uint256[] memory requested."

Please consider this contract: pragma solidity 0.8.7; contract Test { struct UserStruct { uint256 betAmount; uint256[] potentialWinnings; string teamChosen;} mapping(address => UserStruct[]) public userStructs; function appendUserBet(string memory userTeamChosen,uint256 eventNumber) public payable { UserStruct memory userStruct = UserStruct(msg.value,new uint256[](0),userTeamChosen); userStructs[msg.sender].push(userStruct);} function updatePotentialWinnings(uint256 eventNumber,address userId,uint256[] memory potentialWinnings) public { userStructs[userId][eventNumber].potentialWinnings = potentialWinnings;}} It works fine, however when::Listen

Please consider this contract:

pragma solidity 0.8.7;  contract Test {      struct UserStruct {         uint256 betAmount;         uint256[] potentialWinnings;         string teamChosen;}      mapping(address => UserStruct[]) public userStructs;      function appendUserBet(string memory userTeamChosen,uint256 eventNumber) public payable {         UserStruct memory userStruct = UserStruct(msg.value,new uint256[](0),userTeamChosen);         userStructs[msg.sender].push(userStruct);}      function updatePotentialWinnings(uint256 eventNumber,address userId,uint256[] memory potentialWinnings) public {         userStructs[userId][eventNumber].potentialWinnings = potentialWinnings;}} 

It works fine, however when I’m including a function below to the contract, it doesn’t compile. It errors out with TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256 to uint256[] memory requested.

    function addAllPotentialWinnings(uint256 _eventNumber, uint256[] memory _potentialWinnings, address[] memory _usersList) public {         for (uint i =0; i<_usersList.length;i++){             updatePotentialWinnings(_eventNumber,_usersList[i],_potentialWinnings[i]);}} 

I want to provide an array of arrays (2D-array of dynamic size) as an argument to the function, but I seem to be doing it incorrectly. From what I was able to understand is that UserStruct expects potentialWinnings to be in uint256[] format, but it recieves them as uint256. By design I want to provide the function with an array that looks like this: [[0,1,2],[2,5,6],[x,y,z],...]

How do I change my contract such that it "knows" that the array i’m passing as an argument, is going to have the required arrays inside?

Thank you in advance!

DFINITY R&D Team Announces BTC-ICP Integration Beta Release

Shopping cart
There are no products in the cart!
Continue shopping
0