Skip to main content

Questions tagged [solidity]

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.

Filter by
Sorted by
Tagged with
19 votes
1 answer
6k views

What are the attributes of the `msg` object and how can I list them?

I know msg.sender exists, it gives the address of the sender. What other attributes are there and how can I list them / where are they defined?
TMOTTM's user avatar
  • 1,953
18 votes
4 answers
22k views

Delete all elements from an array?

I am writing a smart contract to be the backend of a game. Instead of using a mapping, I have decided to use an array to store the addresses of accounts who have paid my contract. (I know it is common ...
Bryan Campbell's user avatar
18 votes
6 answers
14k views

How to retrieve revert() reason for past transactions?

I run a geth/parity node for broadcasting user's transactions to Ethereum blockchain. Some of contract functions provide reasons for revert (see example below): contract Example { function test (...
user3184743's user avatar
18 votes
3 answers
10k views

How can you share a struct definition between contracts in separate files?

I can't declare a stand-alone struct in its own file, what gives?
pfrank's user avatar
  • 716
18 votes
2 answers
17k views

Call contract and send value from Solidity

I have a pre-deployed contractA with known ABI. I would like to call function func1(string,string) in the contractA (and pass the arguments) from a new contractB and send some value at the same time. ...
k-zar's user avatar
  • 442
18 votes
3 answers
21k views

How to do Solidity percentage calculation?

I'm trying to calculate a percentage of a number in solidity with the following code. The percentage is technically basis points (10000ths, instead of 100ths) because I want decimal percentage values....
Svante's user avatar
  • 450
18 votes
2 answers
17k views

Truffle: how to get balance of any address or contract's address

For example I have a testing block like this: contract('CreeptomaPresale', function(accounts) { describe("adopted over allow quantity", function () { it("test get balance", async function ...
hqt's user avatar
  • 449
18 votes
4 answers
8k views

How can I call a constant function without spending any gas inside a transaction function?

I have a sorted linked list that contains around 1000 items. When I receive a new item my goal is to push the item to the list keeping the sorted order. So if I receive very small value, I am required ...
alper's user avatar
  • 8,394
18 votes
4 answers
7k views

How to unit test contract private and internal functions?

How can we unit test contract private functions using the Truffle framework? Since Solidity doesn't have package access or reflection language features, standard private testing approaches don't work....
Daniel Que's user avatar
18 votes
6 answers
37k views

send ethers from one contract to another

I am wondering how can I have ethers in my contract. I have 2 contracts associated with different accounts. I want to send ethers from one contract to another but how do I have ethers in my contract ...
Pawan's user avatar
  • 191
18 votes
1 answer
14k views

Member function "transfer" not found or not visible after argument-dependent lookup in contract?

I am having a problem with my smart contract making value transfers. My current environment: Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2) Solidity v0.5.0 (solc-js) Node v8.11.1 I created the ...
Robert Oschler's user avatar
18 votes
3 answers
16k views

Contract address.transfer method gas cost

Who will pay the gas in the following scenario? Lets say we have the following simple function. That sends an amount from the contract back to the sender.. just an example. function withdraw() ...
Cody Popham's user avatar
18 votes
1 answer
24k views

How to read public variable from contract using ethers.js

I am trying to read public variable from contract on chain using ethers.js. Calling the methods work but I could not manage to read public property (without getter). The methods works like this: const ...
senty's user avatar
  • 297
18 votes
1 answer
5k views

Can a contract with no payable function have ether?

The question in the title says it all. To the best of my understanding, the only way to deposit ether into a contract is by calling a payable function, and set msg.value larger than 0 (and of course, ...
goodvibration's user avatar
18 votes
1 answer
29k views

What does Solidity's "call" function mean?

address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName"); //1 nameReg.call(bytes4(sha3("fun(uint256)")), a); //2 if(!nameReg.call.value(10)){throw;} //3 Here ...
Jim Green's user avatar
  • 687
18 votes
2 answers
2k views

What does bytecode of blank contract do?

When I compile a blank contract: contract A {} with solc --optimize --optimize-runs 300000 --opcodes test.sol I get: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x6 DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY ...
Brian's user avatar
  • 243
18 votes
2 answers
4k views

How can I check if a contract has self-destructed in Solidity?

I have got a problem: I have a contract factory that creates some temporary contracts. I want every contract to exist for about 5 days, afterwards, it self-destructs. However, I want to create a ...
Bot X's user avatar
  • 245
18 votes
1 answer
8k views

Inheritance and Function Overwriting: Who can call the parent function?

I want to know who is still able to call an original overwritten function in case of inheritance. Let's assume I have the following setup: contract A{ address public owner; function A(){ ...
SmCaterpillar's user avatar
18 votes
1 answer
3k views

Execution of Fallback function with more 2300 gas

I have tested a contract having a fallback function which updated a state variable (cost 5000 gas). I sent an amount of Ether to this contract with 100000 gas limit. The transaction is valid. As ...
Luan Do The's user avatar
18 votes
2 answers
5k views

Contract reading a string returned by another contract

I have 2 contracts, Parents and Child which has a public string variable - name. contract Child { string public name; function child (string _name){ name = _name; } } Parents ...
shultz's user avatar
  • 1,091
18 votes
1 answer
2k views

Concealing sensitive data in a public contract

I have some sensitive data I'd like to keep in my contract in privacy. I'd like to make a simple version of Zero-Knowledge Proofs and have an idea in mind. Let's say I have a customer who filled out ...
Igor Barinov's user avatar
  • 2,138
17 votes
4 answers
6k views

What is the purpose of giving name to return variables in function declaration?

How is this : function myFunc() returns(uint a){} different from this: function myFunc() returns(uint){}
Kashish Khullar's user avatar
17 votes
4 answers
25k views

What is the maximum value an int and uint can store

I need to understand a couple of things: What is the maximum value an int and uint can store? Are the maximum values stored in int and uint the same?
iappmaker's user avatar
  • 813
17 votes
1 answer
19k views

Solidity: private vs public variables

In a smart contract, if we make a member variable public: Question 1: Can a malicious party write a transaction/contract and change the value/state of the public variable in the contract? Question 2: ...
Aydin's user avatar
  • 2,117
17 votes
1 answer
18k views

truffle migrate: How to deploy a contract whose constructor takes a parameter

I'm using Truffle Version 4 to develop a simple smart contract and am stuck on something I think reflects a very basic misunderstanding that I just can't get my head around. Here's my simple contract,...
Dave Sag's user avatar
  • 879
17 votes
2 answers
29k views

Return a mapping in a getAll function

pragma solidity ^0.4.24; contract User { mapping(uint=>address) addresses; uint addressRegistryCount; function set(address userAddress) public { addresses[...
UnexpectedCharacter's user avatar
17 votes
2 answers
22k views

calldata keyword as parameter in solidity v0.5.0 function?

What purpose does the "calldata" serve in this parameter _owners? Is it a new keyword? function setup(address[] calldata _owners, uint256 _threshold, address to, bytes calldata data) Taken from ...
Lul Bai's user avatar
  • 191
17 votes
3 answers
20k views

How to initialize an empty array inside a struct?

Is there a mistake in the way I initialize Bar b in the function foobar? contract Foo { struct Bar { address owner; uint[] x; } Bar[] public bars; function foobar(...
Manan Mehta's user avatar
17 votes
3 answers
15k views

How to use bignumbers in truffle tests?

I am testing a smartcontract with Truffle V5. All works well if I do not use all decimals. If I set 18 decimals all explodes. The test code is this (from truffle docs): const MetaCoin = artifacts....
PragMan's user avatar
  • 173
17 votes
2 answers
5k views

does revert()/require() revert changes made to other contracts?

Let's say I call functions from several external contracts in a function and check for their return values (given the fact they return a bool) either with require() or revert(). Pseudocode: function ...
Daniel Gretzke's user avatar
17 votes
7 answers
21k views

How to convert string to int

How do i convert a string into a int? here is my code: pragma solidity ^0.4.6; contract MyContract { string public a; /* Constructor */ function MyContract() { a = "0....
Fadil's user avatar
  • 171
17 votes
3 answers
16k views

What's the proper way to wait for a transaction to be mined and get the results? [duplicate]

I'm using react to write the frontend for my dApp, and doing this to (attempt to) update react's state via an asynchronous sendTransaction call: var thisJS = this web3.eth.sendTransaction({from: ...
glowkeeper's user avatar
17 votes
1 answer
12k views

now keyword in Solidity

I was unable to find any relevant documentation for the now keyword within the Solidity documentation, other than its usage in examples. What exactly does the now keyword return, how is it determined ...
Michael's user avatar
  • 1,075
17 votes
5 answers
21k views

What is the best way to get the JSON ABI after deploying a contract with Truffle to Ganache or Kovan?

Remix makes it so easy to get the JSON ABI. Does anyone have any recommendation on how best to get the JSON ABI after successfully deploying a contract using Truffle without having to leverage Remix?
wardsback's user avatar
  • 399
17 votes
2 answers
2k views

Can Solidity view/pure functions be arbitrarily complex?

Non-constant functions are limited in computational complexity by the block gas limit. I assume, but am not sure, that this does not apply to view/pure functions. Are view/pure functions in any way ...
SCBuergel's user avatar
  • 8,774
17 votes
2 answers
8k views

Multiple Inheritance and Linearization

Hello to everyone. I am looking at multiple inheritance in Solidity. I came across this example within their documentation, but it is not understandable enought for me. Can someone explane this ...
branko terzic's user avatar
17 votes
4 answers
10k views

What are the best practices to allow user signup and login for a dapp?

From what I have researched, it seems that all of the methods for allowing a user to signup and login for an Ethereum dapp are very cumbersome for the user to use. What are the best practices to allow ...
Jason Cochran's user avatar
17 votes
6 answers
1k views

Can a solidity compiler be written in solidity?

Can a solidity compiler be written in solidity? How much gas would it cost?
Fernando Tiberti's user avatar
17 votes
9 answers
18k views

The endpoint returned a different chain ID: 0x539 (Ganache)

I am trying to connect Metamask to ganache by creating a custom RPC with the following details: New RPC URL: HTTP://127.0.0.1:7545 Chain Id: 5777 But I keep getting the error message The endpoint ...
Chidi Nkwocha's user avatar
17 votes
2 answers
9k views

Convert struct to bytes in Solidity

Is there any convenient way to convert (e.g. cast) a struct type to bytes? I'm trying to call a method like the one below (taken from here) where you can pass some (arbitrary) contextual info that ...
jlpiedrahita's user avatar
17 votes
1 answer
11k views

Passing an array as a parameter from javascrpt (web3) to a Solidity function

I have the following Solidity function: function func(bytes32[2] data) external { bytes32 x; bytes32 y; x = data[0]; y = data[1]; } I'm trying to call it from ...
Eyal Ron's user avatar
  • 321
16 votes
10 answers
15k views

How to convert an bytes to address in Solidity?

How to convert bytes or string (eg: 0xf2bd5de8b57ebfc45dcee97524a7a08fccc80aef) to address in solidity?
徐欢欢's user avatar
  • 163
16 votes
3 answers
36k views

invalid arrayify value while using bytes32 array

Since we cannot pass string arrays as parameters in solidity I used a byte32 array in a function. The code gives no error at compile time. But when I give input to the drawCard function as below in ...
mzaidi's user avatar
  • 1,012
16 votes
5 answers
14k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
arete's user avatar
  • 609
16 votes
1 answer
8k views

Why does ++i cost less gas than i++?

Why in solidity, i++ & ++i works the same but one costs a little bit more gas? Take a look at this contract: contract foobar { uint[] public arr = [1,2,3,4,5]; function find() public ...
DevABDee's user avatar
  • 473
16 votes
8 answers
24k views

Solved: How to change Solidity linter [solc] compiler version in Visual Studio Code?

Hi may I know how to change my Solidity linter compiler version in Visual Studio Code(vscode)? OR Visual studio code how to specify solidity compiler version? The only Solidity related extensions I ...
Russo's user avatar
  • 1,784
16 votes
1 answer
8k views

What fixed or float point math libraries are available in Solidity?

Solidity doesn't have fixed-point, floating-point, or double types. What solutions are there to handle the cases where we really have to represent numbers as percentages or fractions?
Paul Razvan Berg's user avatar
16 votes
4 answers
13k views

are there "public" ethereum nodes? or any recommendations on hosting solutions?

I've always ran apps on Heroku. Just developed a smart contract and I need to check the blockchain from the app. Are there public nodes I can connect to to get the info I need to show on my app? If ...
Anto's user avatar
  • 311
16 votes
5 answers
39k views

Solidity: Is there a way to get the timestamp of a transaction that executed?

Is there a way for a contract to be able to get the exact time someone called a function in it? For example, if someone sends funds to the contract address, is there a timestamp recorded by the ...
Pabi's user avatar
  • 1,129
16 votes
6 answers
15k views

Sorting an Array of integer with Ethereum

I'm trying to have a simple array of integer sorted in Solidity but i couldn't find any real ressources so instead i'm trying to do it "the hard way" but so far with very little success. Is anyone ...
user697's user avatar
  • 2,196

1
3 4
5
6 7
358