Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 24693

Solidity is a contract-oriented, high-level language whose syntax is similar to that of JavaScript and it is designed for writing smart contracts in Ethereum to run on the EVM. Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.

1 vote
Accepted

Can I use variables declared in modifiers in my function?

pragma solidity ^0.4.24; contract ModifierTest { address public owner; struct myStruct { uint256 fancyVar; } constructor() public { owner = msg.sender; } modifier …
Paul Razvan Berg's user avatar
2 votes

return value from revert using web3

Unfortunately, as of the latest version of Solidity (0.4.24) and the EVM, this is not possible. The transaction is reverted and that's it. …
Paul Razvan Berg's user avatar
1 vote
Accepted

Check "type" of ERC20 token

There's a mistake in your code. You never pass the address of msg.sender to an interface constructor. The solution to always interact with USDT is to store its address as a constant. address public co …
Paul Razvan Berg's user avatar
2 votes
1 answer
676 views

How to read partial values from a tuple?

How to read only some variables from a tuple returned by a function in Solidity? …
Paul Razvan Berg's user avatar
3 votes
Accepted

How to read partial values from a tuple?

Just use commas: /* SPDX-License-Identifier: LGPL-3.0-or-later */ pragma solidity ^0.7.1; contract TupleTest { function foo() public pure returns (uint256 left, uint256 middle, uint256 right) …
Paul Razvan Berg's user avatar
5 votes
Accepted

Parsing solidity bytes to params

You can use the Solidity built-in function abi.decode for this. …
Paul Razvan Berg's user avatar
1 vote
1 answer
387 views

How would a regex statement for Solidity pragmas look like?

Does someone have a ready-to-use regex for Solidity pragmas? I need to perform certain actions based on what pragma the user wishes to use. (I'm writing a utility for Foundry.) …
Paul Razvan Berg's user avatar
2 votes

How do I define a public function in a Solidity interface?

As per the Solidity documentation: Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions: ... … MyContract is MyInterface { function foo(bytes memory b) public view returns (bool) { ... } } Note: there are two additional parameters, virtual and override, to be cognizant of if you're using Solidity
Paul Razvan Berg's user avatar
1 vote

Can Mapping be public inside a struct?

A struct is an abstract data structure, struct member don't have any visibility. Only variables that are defined using the struct type can have visibility modifiers. Therefore, you should delete the p …
Paul Razvan Berg's user avatar
0 votes

global vars and objects

There's a section in the Solidity docs for this: Units and Globally Available Variables For example, block.timestamp returns the current Unix timestamp recorded in the Ethereum blockchain. …
Paul Razvan Berg's user avatar
2 votes

Is there a function in Solidity to load data, i.e a .txt or .csv, into a smart contract

Solidity cannot handle "txt" or "csv" files directly. In fact, at runtime, all there is the blockchain state. Solidity cannot communicate with the external world (not even via the HTTP protocol). …
Paul Razvan Berg's user avatar
1 vote

How to get wallet balance of a token given token contract address and wallet address in Soli...

Just import the IERC20 interface from OpenZeppelin and then do this: IERC20(contractAddress).balanceOf
Paul Razvan Berg's user avatar
1 vote

Detect whether a contract can handle ERC20 or not

It's unclear what you mean by "handle", but assuming you mean "react to an ERC-20 transfer", this is not possible. The ERC-20 standard did not specify callbacks (a.k.a. hooks), unlike other token stan …
Paul Razvan Berg's user avatar
13 votes

How to check if a contract has a method?

ERC165 tackles this problem but it cannot be used for older ERCs. For instance, most ERC20 implementations don't implement it (as of Nov 2018, at least OpenZeppelin doesn't). You could try calling the …
Paul Razvan Berg's user avatar
2 votes
2 answers
6k views

How does solidity handle mod 0?

Imagine you have a function like this: function compute(uint256 a, uint256 b) external pure returns (uint256) { return a % b; } Does it revert when b is 0?
Paul Razvan Berg's user avatar

1
2 3 4 5
14
15 30 50 per page