Stack Exchange Network

Stack Exchange network consists of 174 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 [contract-development]

Questions regarding the development of smart contracts

147
votes
11answers
28k views

Upgradeable smart contracts

If the contract issuer wants to have a way to upgrade the contract code, so that account data and other things carry over, can Ethereum provide for this? Also can this be done without changing the ...
100
votes
2answers
18k views

Are there well-solved and simple storage patterns for Solidity?

Simple and appropriate data organization can challenge Solidity newcomers. It wants us to organize everything in ways many of us aren’t accustomed to. Are there well-solved general patterns for ...
85
votes
5answers
25k views

How can an Ethereum contract get data from a website?

What is the process/workflow behind the process where an Ethereum contract gets some data from a website?
83
votes
7answers
30k views

What is an ABI and why is it needed to interact with contracts?

ABI is referenced in many places including the official Ethereum website. What is an ABI and why is it necessary to use?
61
votes
3answers
19k views

Difference between require and assert and the difference between revert and throw

I was looking at the docs and Im looking for clarification on the difference between require and assert and throw and revert. assert(bool condition): abort execution and revert state changes if ...
45
votes
3answers
7k views

What is a recursive calling vulnerability?

What is a recursive calling vulnerability exactly? When creating smart contracts, DAOs or DAPPs, what measures can I take to ensure I am not vulnerable?
37
votes
3answers
14k views

What is the zero, empty or null value of a struct?

If I have a mapping of string => custom defined struct, how do I check if a value is defined in the mapping? The docs state that "every possible key exists and is mapped to a value whose byte-...
37
votes
2answers
22k views

What is an Event?

What is an Event? Are they only used in Solidity? How are events defined? How are events initiated? Is there a standard term for an event's invocation (do you say an event "happened", "was called",...
34
votes
8answers
17k views

How to quickly test a Solidity function?

There are snippets and functions of Solidity code provided on this Ethereum Stack Exchange and other sites. What are ways to quickly test them, possibly debug a little, and play around?
34
votes
5answers
22k views

How to delete an element at a certain index in an array?

Anyone know how to delete an element in a array? Is there any built in method to do that? If not, does anyone know of how to implement such a method?
33
votes
6answers
27k views

How do you get a json file (ABI) from a known contract address?

I want to watch a Solidity contract using the Mist browser. I know how to do that and it needs the address and the json. I have the address, but I don't have the json. I do have the source code. Can ...
30
votes
5answers
14k views

How can I debug a smart contract?

When developing my smart contract, how can I debug it? Are there any debugging, testing tools or simulators that I can use to examine my code?
29
votes
2answers
18k views

Solidity, create contract from contract

Based on documentation it should be possible to create new contract from contract contractAddress = new OwnedToken(name); When I invoke this method from contract, the address I receive seems to be ...
28
votes
8answers
12k views

What are the development tools for Ethereum?

Could someone make a list with development tools for Ethereum together with a short description what they are good for?
28
votes
2answers
19k views

Use string type or bytes32?

What are the benefits to using string datatypes over bytes32 to represent text data. It seems my contract runs into an out of gas exception when I switch the data structures from bytes32 to string.
28
votes
1answer
21k views

How to Initialize a Struct?

I have a struct like so : struct fooStruct { uint foo; uint figther; } I would like to initialize that struct but it won't be stored in a mapping but inside an array. Is there a way to ...
28
votes
2answers
6k views

Why do Solidity examples use bytes32 type instead of string?

In many Solidity examples I read that use strings for parameters or return values, I see they are typed as bytes32 although there's a string type. What is the real reason for that? Thanks.
27
votes
5answers
17k views

How to concatenate strings in solidity?

I'm trying to concatenate two strings in solidity. I tried with + or . but neither option works. There is not much documentation on string concatenation yet. Is it even possible? If not, can I ...
26
votes
2answers
18k views

How does Mapping in solidity work?

I went through the Crowdfunding example in solidity where i encountered the following: contract Crowdfunding { struct CampaignData { address recipient; uint contributed; uint goal; ...
25
votes
3answers
13k views

How to create a Dapp from scratch on Ethereum?

Let's say we have someone who knows about blockchain but who doesn't have any background in blockchain-based application. That person wants to code an ethereum-based Dapp (decentralized application) ...
25
votes
3answers
10k views

How to write an optimized (gas-cost) smart contract?

As we all know, there are many factors that determine a good smart contract, such as: Security: it has minimal/zero vulnerability so they cannot be exploited by an adversary. Immune to Attacks. Cost:...
25
votes
1answer
14k views

How to update a deployed smart contract? [duplicate]

I've started developing smart contracts with Truffle and when I edit a contract I always redeploy it by adding another migration script. There are two things that I wonder about: Is this the way it ...
24
votes
4answers
5k views

Error while compiling: Stack too deep

When trying to compile, I am getting the following error: "Internal compiler error: Stack too deep, try removing local variables." Is there any way around this? I'm not sure if I'll be able to ...
23
votes
4answers
7k views

What public test-networks and faucets exist?

What public test-networks exist and what are their conditions? What are the connection data? How often (if so) are they reset? Does a public faucet exist for this test network? Does a block explorer ...
23
votes
2answers
8k views

'internal' keyword in a function definition in Solidity

Does the internal keyword in a function definition such as: function doSomeThing(uint _param) internal {...} work similar to designating a method as private in other languages and thus makes the ...
23
votes
1answer
8k views

Cannot perform write functions in smart contract - invalid address?

I have the following simple smart contract... contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) ...
22
votes
3answers
16k views

Returning a struct and reading via Web3

I am storing data in my contract using a mapping of structs. For examples sake, say I'm storing employee info (name/address/salary), mapped by their employee ID. Via a web front-end, I'd like to be ...
21
votes
1answer
8k views

Ways to see if address is empty

Is owner > 0x0 a good way to test if an address owner was set in Solidity? I am not sure if this could break something in the future and if there are better ways to see if the address was set. What ...
21
votes
3answers
10k views

How can I represent decimal values in Solidity?

I just started writing some solidity and I noticed that there are no decimal values such as double or float. What do you guys do when you need to return send to a wallet let's say 1.57 ether? Or when ...
21
votes
1answer
1k views

How does the solidity optimizer work?

The compiler for solidity supports the flag --optimize which performs some set of optimizations to the compiled solidity code, typically resulting in a reduction of gas costs. How does the optimizer ...
20
votes
4answers
6k views

How to store IPFS hash using bytes?

Following Q/A (What datatype should I use for an IPFS address hash?) recommend us to use bytes to store IPFS hash. I was using following example(https://github.com/AdrianClv/ethereum-ipfs/blob/master/...
19
votes
3answers
25k views

How to call my contract's function using sendTransaction

This may be a very basic question, I don't know why but I am unable to find correct solution to how can I call my contract's method using sendTransaction. I have a transfer(address, uint256) function ...
19
votes
2answers
2k views

Private info in an Ethereum smart contract

Is there any way to store info on a smart contract, and keep it a secret? If a contract has a state variable that is not public like: contract foo{ uint public publicVariable; uint notPublic;...
19
votes
3answers
4k views

Pass a function as a parameter in Solidity

Can you pass a function as a parameter in Solidity? My guess: There is the concept of address in Solidity, but they represent contracts. Contracts can have fallback functions, but I don't think you ...
18
votes
2answers
14k views

Can we get all elements stored in a mapping in the contract

Can we get all elements stored in a mapping in the contract using web3.js ?
18
votes
2answers
9k views

How can you call a payable function in another contract with arguments and send funds?

I have a contract named Call: contract Call { ... function () payable { // TODO: Call the call function in the main contract // and forward all funds (msg.value) sent to this contract ...
18
votes
6answers
10k views

Truffle deployment on test network says: Error: exceeds block gas limit

I'm trying to deploy a sample contract (following this guide) but I'm receiving an error of not enough gas. I changed the numbers a little but could not fix it. I saw this question in stack exchange ...
18
votes
2answers
3k views

Explanation of Parity Library Suicide

So today, A vulnerability found within the Parity walletLibrary which resulted in freezings of potentially hundreds of millions of dollars from wallets using parity multi-sig. Can someone technically ...
18
votes
7answers
3k views

Source code formatter for Solidity?

Most programming languages have tools to format source code according to convention: for example, Python has autopep8 and yapf, and Go has gofmt. Does a similar tool exist for Solidity source code, ...
18
votes
1answer
7k views

Deploy contract from contract in Solidity

It's a common pattern to use a hub/factory contract to create multiple instances of a standard contract. It's also common to require a way to enumerate the addresses of the created contracts. Is ...
18
votes
2answers
2k views

Methodological security review of a smart contract

Is there a tool, checklist of methodology to help reviewing smart contract security? E.g. for each of function you review Is there re-entry possibility and how it behaves on re-entry How it behaves ...
17
votes
2answers
9k views

Is there a way to find an account's current transaction nonce?

I need to know my transaction nonce because I am doing fancy stuff with contract addresses (which are the keccak hash of my address + my transaction nonce). Is there a way to find this through the ...
17
votes
4answers
9k views

How does one contract send ether to another contract with more than 2300 gas?

I want one contract to collect a certain amount of finney before sending it to another contract, but I can't simply send in with C2.send(thisMuch). function() { Dividend m = Dividend(dividendAddr)...
17
votes
1answer
8k views

How to delete an element from a mapping?

I have a mapping like this: struct data { string name; string nickname; } mapping(address => data) public user; What is the correct way to delete one element from the variable user? ...
16
votes
2answers
13k views

How can I return multiple strings from a contract function?

In solidity it's obvious how to get a single string returned from a function. But, I'd like to have the smart contract return multiple string values. Is there a way to do this?
16
votes
1answer
3k views

How to access external knowledge / data in a smart contract

let’s say a contract wants to execute on knowledge contained outside the blockchain (e.g. whats the price of gold, what was the avg windspeed in NYC, how many people moved to portland in the last ...
16
votes
3answers
4k views

How do I specify a different Solidity version in a Truffle contract?

I've got a contract where I want to use <address>.transfer(), which was released in the latest Solidity version 0.4.10. I have as the first line of my contract: pragma solidity 0.4.10; but ...
15
votes
3answers
9k views

operator == not compatible with type string storage ref and literal_string

can someone help out with the stated error, i am trying to run a code to check the status of a String variable. while compiling using the online solidity compiler i am getting two errors on ...
15
votes
2answers
3k views

What is the purpose of underscores in front of parameters?

I see contracts that use underscores in front of parameter names, like so: function Greeter(string _greeting) public { greeting = _greeting; } What's the purpose of these underscores? Do they ...
15
votes
2answers
1k views

Why are local variables allocated to storage instead of memory?

Local variables (i.e. variables declared inside functions) are held in persistent storage by default instead of non-persistent memory (source). The value of a local variable can not persist in ...