New answers tagged

0

I am not sure about the end-functionality of your code in the terms of what you are looking to accomplish (Gater all the values of all the tokens owner has?) But this commented code should help, I tried to make it as simple as possible. pragma solidity ^0.7.0; contract Function{ function tokenOfOwner(address owner) public virtual returns (uint256[] ...


0

TypeError: This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour. Is perfectly normal as uint256[] storage _ownerAmount; is not initialized, meaning that it defaults to slot 0 possibly overwriting whatever is already occupying that slot. However, looking at your code you probably don't ...


3

It is probably failing because the books array is empty and you're trying to access books[_bookId].isRegistered() over a non existing book. Initialize the books array with values in the Library constructor first. Or, you can introduce a check before accessing variables such as address(books[_bookId]) != address(0)


1

It depends on your Solidity version, so sharing this might help. There are a couple questions with answers around this that might help: Accessing array within struct in a mapping using web3.js Cannot retrieve uint Array from Struct in Solidity


1

In short - it's more expensive. How much depends on how often your have to do it. Expanding a small array like this once is no big deal but if you need to do it repeatedly you should look for alternatives. Here's how it specifically affects gas usage: If you could just increase the size in place, it would be O(1) complexity in terms of computation because ...


1

You allocate new memory each time when you add a new item. At some point allocating memory goes from linear costs to quadratic costs, therefore becoming quite expensive.


0

It looks like there's a problem with the way you format the arguments. Make sure to add quotes around each address (arguments in web3 have to be passed as strings). Also, based on the stack trace you show, you may have a , missing between the addresses as well. e.g. rec: ["0x5B38Da6a701c568545dCfcB03FcB875f56beddC4","...


0

Reference types (arrays, mappings, struct) that are part of the structure are not being returned when you try to return structure data. You can notice that only value types are returned. You should create a function that would act as a getter that will access the data you need and return it back. For your example: function getSources(uint transactionId) ...


1

I suggest you change the way you built your uint256[13] to use uint256[] memory _value = new uint256[](13); instead. Then you should be able to use myFunc(_value). If your array does not always contain 13 elements, you can replace 13 with a variable, like so: uint256 _n = 3; uint256[] memory _value = new uint256[](_n); // populate your array


0

function removeIndex(uint256 index) external { require(index < temp.length); for(uint256 i = index ; i < temp.length - 1; i ++) { temp[i] = temp[i + 1]; } temp.pop(); } Use this piece of code if you want to resize the array and preserve the order of the elements. It is not gas-wise, but for smaller arrays works.


1

I didn't quite understand the depth of the idea, but maybe this option will help: function store(uint256 _myVal) public { myVal.push(_myVal); for(uint256 _y = 0; _y < myVal.length; _y++) if(_y<_arr.length) _arr[_y]=myVal[_y]; else _arr.push(myVal[_y]); }


1

You don't have to worry about that, Yes two miners can receive different version of a transaction like you suspect, they both might mine it as well and broadcast to network, but only one of them will be confirmed and recorded by the network. So best scenario in this case would be to just wait for few confirmations. You can read more about race conditions in ...


1

You can use a code-word delete that sets a variable to its initial value which is all 0's for an array. delete players; You can read on the delete command in the Docs


1

The array is HUGE This is a problem. Given a json file with pairs containing address: value, i need to update the state of the addresses in my contract This is an implementation idea expressed as a requirement. Since the implementation is impractical, it's time to dig in and find out what the actually requirement actually is. WHY? I would expect to hear ...


0

With the Uniswap v3 subgraph: { tokens(where:{symbol:"DAI"}) { name id whitelistPools { id token0 { id symbol } token1 { id symbol } } } } The key here, is whitelistPools: { "data": { "tokens": [ { "id": "...


1

You need an array or some sort of indexing in the mapping to be able to do so. If you choose the indexing option you would still have to do the iteration on the application side and call the payout function for each member of the mapping. Solidity file: struct Receiver { address receiver; bool paidOut; bool isWinner; } mapping(uint => ...


Top 50 recent answers are included