Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [require]

The tag has no usage guidance.

2
votes
3answers
34 views

Should I use require in view functions?

When I call a solidity function to get a struct element, is it a best practice to use require and check if the element exists or should I just return the empty values? Without require: function ...
0
votes
1answer
18 views

Geth Node doesn't revert a transaction not satisfying a require

i'm testing my smart contract on remix with local ganache cli, when i try to test case that doesn't satisfy a require on the SC i correctly receive message "transact to Contract.function errored: VM ...
2
votes
1answer
27 views

How to handle require/revert/assert errors properly

I'm trying to find an easy pattern to revert/rollback a write transaction. The first idea was to log a GenericErrorEvent but then I noticed that it will never be emited if any require/revert/assert ...
1
vote
1answer
55 views

How to get require() to accept decimal value of ether in payable functions in Solidity?

On using, require(msg.value == registerFeeMap[msg.sender] /_currentRate) (fractional ETH value calculated) require(msg.value == registerFeeMap[msg.sender]*10**18/ _currentRate) (ETH converted to ...
1
vote
2answers
27 views

How to use function arguments of payable function for require statement?

function createCampaign(uint deposit, address ll) public payable{ dpst = deposit; require(msg.value > (40*dpst)/100 wei); address newCampaign = address((new Campaign).value(msg.value)(...
2
votes
2answers
20 views

Validate bytes16 argument size

I have a function which accepts one bytes16 argument. function start( bytes16 reference ) I have some events which I use to track behaviour, using reference as the index. Everything works ...
1
vote
1answer
54 views

VM Exception while processing transaction: revert message

When a solidity smart contract reverts with a message due to a failure on a require statement, the browser calling the smart contract returns "Error: VM Exception while processing transaction: revert"....
0
votes
1answer
57 views

Is there a way to know the REAL msg.sender?

I want to know the real msg.sender of the transaction. Which this means is, if I use truffle console I can change the msg.sender by using {from: another address}. So let's say my address is A, and ...
1
vote
1answer
58 views

Why does this function not need a require statement?

Why does the following function not need a require statment? function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][...
1
vote
1answer
148 views

Emit event while require statement fails

I would like to be able to log a result of a condition: if(time > 5) { emit Result("time is larger than 5"); } else { emit Result("time is less than 5"); } This will work just fine, but ...
3
votes
2answers
33 views

Does the require function need more gas when called with a message?

If I add a message to require as a second parameter, will it increase gas consumption?
0
votes
0answers
30 views

Are function modifiers added to the stack in solidity? [duplicate]

I've got a function with a decent number of modifiers and I hit the CompilerError: Stack too deep, try removing local variables error. If I remove one of the modifiers though, everything's all right. ...
1
vote
2answers
33 views

Check given adders transaction history? [closed]

I've created a voting game on eth blockchain. I would like to make a function, that only address with previous transaction history(not a fresh address) can call. So doesn't allow people to create a ...
4
votes
1answer
129 views

how accurate are gas estimates?

I am currently running some tests on ganache using web3.js connector. Most of my transactions run OK if I supply the same amount of gas that is suggested by web3.eth.estimateGas(), however, one of ...
3
votes
1answer
46 views

Setting time requirements in Solidity

I want a function to only be able to be called after a certain specific period of time has passed from the contract's inception. Generally, I was using block.number for that. As in: require(block....
3
votes
1answer
65 views

Access require message

I am using JavaScript to run some tests on my solidity contract. Since solidity ^0.4.22 you can have a message in require such as: function Hello { require(msg.sender == 0x001234, "msg.sender ...
1
vote
1answer
72 views

How to use require() with stings

I am trying to run this code on remix IDE: pragma solidity ^0.4.24; contract Aa { string public result; function feedData(string _result) public { require(_result = "e" , "...
3
votes
1answer
26 views

Contract design by contract -> correctness and maximum gas consumption

This question is a general design question that regards contract correctness and the functions I list here are just examples. As I develop on Ethereum, it becomes aparent to me that it might be ...
0
votes
1answer
77 views

Expect Error: transaction in Truffle [duplicate]

Im testing wheter a require function does its job by reverting and want to test in within a truffle test. it("The URI should be unique", async () =>{ const dupURI = await token....
1
vote
1answer
201 views

Test if a map element has been deleted or does not exist?

I have a map of game IDs to game structs in my Solidity contract. I want to test if a game struct for a given ID does not exist or has been deleted. I am using the code below: // The map that maps ...
2
votes
1answer
756 views

Custom error message in require() not showing up?

I've got Solidity v0.4.24 And I'm doing this: require(false,"this is a test"); When I run truffle test I get the revert, but I cant see the error message. Any ideas what could be wrong?
2
votes
2answers
860 views

Syntax: How do you require a string to be null (or anything but null)?

I want to make sure that when doSomething() is called, the string variable is always populated (that it can't be left blank): function doSomething (string hash) public { require(hash != ...
3
votes
2answers
306 views

Why not use require() in place of assert()?

Even though require() is used substantially more than assert(), there are places where assert() gets used. One example would be in the widely adopted SafeMath library by OpenZeppelin: function add(...
1
vote
2answers
39 views

transfer back msg.value to caller on error

I have a function with modifier 'payable' in the contract. My understading is, msg.value gets added to the contract's balance and then further code is executed. First question, is this a correct ...
1
vote
1answer
106 views

Handling require/assert failure errors correctly from a Node.JS app?

I have a getter function in my smart contract that returns one of the string values in statically defined string array. Upon entry to the function, it does a bounds check on the incoming index using ...
1
vote
0answers
156 views

cannot get return variable(s) in javascript when using require in solidity

I have a function in solidity that returns a few bytes32 variables. I cannot for the life of me access those variables. Can someone please help? function getData() public returns (bytes32, bytes32, ...
0
votes
1answer
26 views

What is an example of a require-style exception when receiving ether via a public getter?

In the Solidity documentation it is stated that: A require-style exception is generated in the following situations: ... If your contract receives Ether via a public getter function. ...
1
vote
1answer
220 views

hardware and software requirements to launch an ERC20 Token

Pardon me I'm new in this. I'm trying to launch my ERC20 token. So What are the hardware and software requirements for an ideal transfers handling server system?
1
vote
1answer
23 views

Are there any downsides to if…else logic versus rejecting in a function

Pretty much all examples of contract functions I see use the require(...) pattern. If the initial condition is not as expected, an error is thrown and the transaction is reverted. I don't like this ...
0
votes
1answer
188 views

Why wouldn't I use require()?

CodeWars SPOILER I'm trying to learn by doing, and I'm pretty confused. I'm working on a kata for making a coin and sending it to others. My solution fails the test because it says I'm not checking ...
0
votes
1answer
151 views

artifact.require() statement with inheritance?

Hi guys my question i very simple. I have this contract: B.sol ... contract A { ... } contract B is A { ... } When i migrate to blockchain my B.sol i need to deploy every single ...
0
votes
1answer
252 views

ERC20 transfer function - Use “if, else” or “require”

Currently, I am planning to implement an ERC20 compliant transfer function in my ERC20 compliant contract as follows: function transfer(address _to, uint256 _amount) public returns (bool success) ...
1
vote
1answer
46 views

Functions with boolean return type while using require()

I am trying to understand the reasoning for this: (for an online class) mapping (uint => uint) public multiplier; /** * Called by the owner of the TollBoothOperator. * Can be used to update a ...
0
votes
1answer
437 views

Remix Warning : Assert

I am trying to compile a contract on remix and have run into the following warning : Use assert(x) if you never ever want x to be false, not in any circumstance (apart from a bug in your code). ...
1
vote
4answers
2k views

Unit testing for assert()/require() in Truffle/Solidity

If I write a function like so: function calculate(int x) public returns (int) { require(x > 0); // Do other stuff return x; } How would I write a JavaScript unit test in Truffle ...
2
votes
1answer
919 views

Solidity multiple vs single require

One of the functions of my smart contract can only be executed if three conditions are met. At the moment I have a single require which combines all the conditions like this: require(evalCond1() &...
0
votes
1answer
145 views

How to add requirements to the token contract: 1) owner has enough tokens and 2) minimum sum of ETH of the receivers before updating balances

Could you check if these lines are correct and will work? In this code I have two requirements: I want to check if the owner has enough tokens (10 millions tokens) before updating balances and also ...
1
vote
0answers
222 views

Catch a “require()” in frontend

I was trying to validate a transaction with some conditions on contract level and was wondering if it was possible in any way to give user feedback in the frontend if a require() fails - aka if it ...
0
votes
3answers
179 views

Require: How to avoid users of my smart contract from losing their ether

I have a smart contract lottery that requires people to send exactly 0.2 ethers to its address in order to participate. In the constructor: ante = 0.2 ether; And in the payable function ...
0
votes
1answer
274 views

Control structure with truffle (assert and require)

When I'm trying to deploy contracts that contain assert and require using truffle I receive Error: Undeclared identifier. e.g: pragma solidity ^0.4.8; contract Owned{ address public owner = ...