current position:Home>How to judge whether a structure is empty in solidity?
How to judge whether a structure is empty in solidity?
2022-02-03 23:37:43 【Q & A of Denglian community】
pragma solidity ^0.6.0;pragma experimental ABIEncoderV2;contract Market { struct Fruit { uint amount; } uint256[] public fruitId; mapping (uint256 => Fruit) private _fruits; function gettotal() public view returns (uint) { return fruitId.length; } function getFruit(uint256 _fruitId) public view returns (Fruit memory) { return _fruits[_fruitId]; } function addFruit(uint256 _fruitId) public { //require(_fruits[_fruitId]== Market.Fruit(0),"added"); It doesn't seem to work 0 Judge _fruits[_fruitId] = Fruit( 0); fruitId.push(_fruitId) ; }}
Add a new id You should judge this fruit Have you added , How to judge this id Is the corresponding structure empty ?
Other answers 1:
Other answers 2:
copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032337408127.html
The sidebar is recommended
- How does library query block information
- How does Ethereum change the consensus mechanism
- The difference between memory and storage temporary variables set in solidity
- Problems of Web3 interaction
- How does truss deploy multi file contracts and merge contract files
- Fail with error 'TransferHelper: TRANSFER_ FROM_ FAILED'
- Can one method in solidity call two methods of transferring tokens
- Ethereum node server
- Course blockchain full stack development - Web3 cannot be imported in the actual practice of Ethereum DAPP development
- Xiaobai learns the development process of Ethereum smart contract DAPP
guess what you like
-
The shared folder with Remix ide enabled locally cannot be connected
-
A timeout pops up at the end of deploying the contract with truss, but there is already a contract on the chain when looking at the chain. Is the contract complete in this case?
-
Will the use of nest Oracle for stable currency exchange have advantages over curve and centralized exchange exchange exchange?
-
Smart contract operation offline program
-
The DAPP browser integrated environment of wallet is insufficient
-
Is there ide code completion and error prompt comparable to remix
-
How does Bellman optimize the performance of proof
-
How do event events in Ethereum solid communicate with java code? Hurry!
-
Web3 calls the smart contract method. Can you call multiple contract methods at one time? Either they all succeed or they all fail
-
Please ask a question about Ethereum chain configuration change
Random recommended
- Stack too deep, try removing local variables.
- Decompiled smart contracts are not understood
- Are there any teachers who solve the technical problems of blockchain and some problems of Ethereum
- After Ethereum calls the transfer, a hash is generated, but there is no uplink
- The for cycle leads to relatively high handling charges
- How to write a contract? You can transfer some Rec20 tokens to it or take it out
- [reward credits] uniswap token pool rewards uni contract with error 'safeerc20: low level call failed'
- Please recommend some Ethereum query and tracking tools
- Can't import be used in Remix
- I want to write a usdt collection and transfer contract. I want to call the transferform interface of usdt in this collection contract, but an error is reported when calling.
- How to set up the latest provider
- What's the use of eip712
- How to ensure that the price entered by the user is appropriate
- I want to give some accounts money according to the frozen proportion, but the result is wrong. What's the problem?
- The three methods of Ganache + truss are different in obtaining the ether balance
- How to develop the info page of uniswap? Do you need a centralized server?
- About credit rewards
- How should eth2 pledge participate?
- web3. JS call problem
- Remix imports ierc20 of openzeppelin Sol error, unable to import '@ openzeppelin / contracts / token / erc20 / safeerc20 sol': File not found
- Daniel, please stay, go north to Shenzhen blockchain post, wait for vacancy, high salary for talents!!!
- [recruitment] [Beijing] [listed company] blockchain project (three and a half years of commercial exploration, DAPP has been implemented) recruits trust architects
- [recruitment] [Beijing] [listed company] blockchain project (three and a half years of commercial exploration, DAPP has been implemented) recruits solid and go engineers
- About loom side chain
- How does imtoken access the "dydx" page to connect wallet and transfer money? (Note: we hope to have specific steps)
- DAPP's WebView website, how to open the website, where we can get our wallet account, so as to realize transfer
- Why is there so much data in eth logs
- geth benchmark
- Can truffle compile offline?
- Ethereum private chain transfer mining is still unsuccessful, please give advice; After the private chain is started, the IP address is not 127.0.0.1. I'm not sure if this is the reason. If so, how to solve it?
- What is the difference between swapexacttokens for tokens supportingfeeontransfer tokens and swapexacttokens for tokens in uniswap?
- eth_ The hash returned by sendrawtransaction is replaced for some reason. How can I determine the new hash of this transaction?
- Is there any way to get the block height of the first transaction of an address on Ethereum?
- Install geth and enter sudo add apt Repository - y PPA: Ethereum / Ethereum. The system has not responded
- How to get the pending transactions in the ETH trading pool?
- A problem with HD Wallet
- Can't you call struct in the interface like this
- Ask you guys how to get started with blockchain development
- Structure nested query problem
- How does the blockchain wallet call the freezing function in the token smart contract