Questions tagged [contract-design]

for high-level questions about the choices made during contract construction

Filter by
Sorted by
Tagged with
8
votes
1answer
5k views

Access struct object of one contract from another

I have 2 contracts: contract Student{ uint ID; struct stu{ string name; uint age; bool tookTest; } mapping(uint => stu) StudentNames; function Student(...
8
votes
2answers
951 views

How many arguments can Solidity take?

I'd like to set lots of arguments in solidity functions. I wonder how many arguments contracts can handle. Does it depend on number of arguments or data size?
7
votes
1answer
18k views

get array.length without a getter from other contract?

Is there a way to get length of an array in an other contract without a getter? pragma solidity ^0.4.11; contract MyContractA { uint[] public myArray; function MyContractA() { ...
6
votes
2answers
1k views

Access all the values (tuples) stored in mappings of solidity smart contract using contract address

This question addresses how a value stored in a contract variable from the outside. Is there any similar way to access a value of tuples stored in mapping(with and without knowing a key of mapping). ...
5
votes
1answer
786 views

What is better, mapping a struct with 2 variables or having 2 mappings?

I have a mapping linking a key and a byte32, and I would like to extend it to store something as long as a byte64. I chose to cut it in half, but what is the best (and lightest) way to store the two ...
4
votes
1answer
531 views

How to reference coin contract already onchain?

In this tutorial: https://dappsforbeginners.wordpress.com/tutorials/interactions-between-contracts/ they talk about interactions between contracts. However, the metacoin contract appears to be in the ...
4
votes
1answer
441 views

What's the minimum token contract interface to be showed in mist?

I would like to implement a contract where users can see their token balance in the mist. In the same way that The DAO does. What's the standard interface I should implement? Is there a standard ...
3
votes
1answer
3k views

VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if

Hi Guys 👋 I have two contacts first one is SubToken and second one is MainContract. First I deploy MainContract after that I use createNewContract function and I create new SubToken. and then I ...
3
votes
2answers
286 views

What happens when you put an recursive schedule call with Ethereum Alarm Clock scheduler?

My goal is to schedule a call once every day. [Q] Is it possible to use recursive function to schedule a call once every day using Ethereum Alarm Clock scheduler? Example from following answer ...
2
votes
2answers
429 views

Why immutable contracts [closed]

I'm a seasoned engineer, but quite new to blockchain technologies. I'm trying to grasp the "why" and the real "value" of immutable contracts. Never seen or heard of pieces of software being ...
2
votes
2answers
437 views

Solidity modifiers: good or bad?

I've heard arguments both for and against Solidity modifiers. On the one hand, they make the code very readable, and the intents behind the calls are very clear. On the other, they increase the ...
2
votes
2answers
976 views

Is it possible for a smart contract to be able to adjust it's conditions based on the current value of Ethereum?

I ask this because I want to create a crowdfunding smart contract for a platform much like Kickstarter. At this point, the only crypto asset I want the contract to raise is Ether with the possibility ...
2
votes
2answers
233 views

What are the risks of using tokens that appear to have ERC20 standard?

Say someone sends some ERC20 (supposedly) tokens to my ETH address. I then use transfer() function to send these tokens to some other address. The question is - by using a "transfer" function do I ...
1
vote
0answers
61 views

Ethereum cost - how does it work in memory

This is really bugging me and doesn't seem any article that can help at all. wiki says further the gas costs for using memory: The fee for expanding memory is determined via a subtract-the-integrals ...
1
vote
3answers
144 views

how does commit/reveal solve front-running?

I am trying to make sure I understand something correctly, so I will pose a problem with a solution. Problem: Let's say commit has been called. After this, we call the reveal. attacker listens to ...
1
vote
1answer
520 views

How to register USER in my Smart Contract using Solidity?

I can't figure out how do we register user in smart contract and get the userdata when he/she tries to login after register through our website..I didn't see any article regarding this..Kindly ...
0
votes
1answer
58 views

why does this contract ask to increase gas limit?

string test; function assemblyStorage() public payable returns (string memory a){ test = "good"; assembly { a:=sload(0) } } I am trying to return the string ...
0
votes
1answer
153 views

Identical contract functions in interface with different inputs

In the ERC721 interface, you have two functions with the same name: function transferFrom(address _from, address _to, uint256 _tokenId) public; function transferFrom(address _from, address _to, ...
0
votes
1answer
102 views

What is wrong with this code, deployed but showing error while sending ether?

I have tried to compile this code for crowdsale and also have deployed the contract on Rinkeby Network. But each time I send a transaction, it says Warning! Error Encounter during Contract Execution [...
0
votes
2answers
194 views

Solidity contract reentry attacked

The idea is to have a user call send() with some eth. The contract decides if user won/lost. Winner gets a prize msg.sender.transfer(msg.value + winnings); loser gets nothing. Unfortunately the ...
0
votes
1answer
370 views

How to define a dynamic struct “field”?

We have a struct as follows : struct ObjectStruct { bytes32 state; address owner; bool isObject; } mapping(bytes32 => ObjectStruct) public objectStructs; bytes32[] ...
12
votes
1answer
6k views

How to write my first Solidity “Hello World” smart contract?

I have never written a smart contract before because there is a lot attached to it getting it working. But I finally want to learn it now. I want to write a simple mininmal working smart contract ...
15
votes
4answers
2k views

What design patterns are appropriate for data structure modification within Ethereum smart contracts?

I am looking to hear about design patterns that people have implemented within Ethereum smart contracts to allow for post deploy modification of data structures. For example, say I have a contract ...
14
votes
3answers
3k views

What are some examples of how inline assembly benefits smart contract development?

A lot of people have expressed excitement at the potential of using inline assembly in smart contracts. After seeing this comment on reddit I'm curious to see some basic (and more advanced, if you ...
14
votes
4answers
719 views

What is the Identity function and what are its uses?

The contract at address 0x04 is the identity function. What is it and what are use cases for it?
10
votes
1answer
2k views

How to edit a contract that has already been deployed? [duplicate]

I have been writing my first few contracts. So, as I understand it, once you write, compile, and deploy your contract, the only way to then interact with that contract is via something like web3.js ...
10
votes
2answers
3k views

Large contract (bytecode >= 45K) causes out-of-gas on deploy

I need some advice about handling a large contract. At a certain size it causes an out-of-gas error when I deploy to a local testrpc node. I experience this when the bytecode reaches approximately 45K....
7
votes
2answers
601 views

Are there any best practices for optimizing computations?

As complex computations cost a lot of gas (sometimes more than actually forecasted), so are there any popular ways or techniques where I can optimize a complex computation to a simplified version of ...
15
votes
2answers
3k views

How can ERC20 token implementations be verified?

The ERC20 Token Standard is great, in that it allows wallets, exchanges, and client implementations to allow users to interface with a variety of tokens in a common way. But how can one of these ...
10
votes
1answer
10k 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:...
8
votes
2answers
1k views

How to make a library address updatable

I want to write a contract that uses a library. This library should be exchangable. Meaning I want the contract to have an updatable (only by owner) address variable always pointing to the current ...
5
votes
1answer
280 views

What happens if you chained delegatecalls?

Solidity docs say "only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract." This is useful when creating a library. But what happens ...
4
votes
1answer
5k views

Store addresses in array or mapping?

My contract currently serves an array of addresses to a front-end: address[] public addresses; function getAddresses() public view returns (address[]) { return addresses; } I'm concerned about ...
14
votes
7answers
12k views

Can I write and deploy smart contracts in Java language?

I am a Java developer. I want to write a smart contract using Java and deploy it to a private blockchain network. Does Ethereum provide the facility to write smart contracts using Java language? If ...
10
votes
2answers
3k views

Why do smart contract languages need to be deterministic?

I read somewhere that smart contract languages need to be deterministic. Why?
5
votes
2answers
1k views

Is it possible to deploy a contract using create2 in Solidity?

Can I deploy a contract in Solidity (not in-line assembly) using create2?
15
votes
5answers
3k views

What is the difference between a smart contract and a DAO?

The Ethereum space is full of new terminology, and it's sometimes difficult to mentally discriminate between some of the concepts that this new terminology describes. (I'm having this trouble now... ) ...
12
votes
1answer
372 views

How growing contract storage increases the gas spending?

I have some further questions about this and this threads. For simplicity, let's imagine that I want to create a cryptocurrency on top of ethereum. The contract that "handles" this cryptocurrency ...
11
votes
2answers
2k views

Should I use 'bytes' or 'string' always?

So after my understandings, bytes and strings are basically doing the same just in different formats and using bytes is cheaper -leading to my question, should I then only use string for data that is ...
8
votes
5answers
1k views

What are legitimate uses of tx.origin?

It is known that msg.sender must be used for authentication instead of tx.origin (the difference explained here). Some static analysis tools (e.g., in Remix) detect all usages of tx.origin as ...
7
votes
1answer
3k views

Store a mapping of addresses linked to arrays of structs

How would I have the following data structure be saved in an Ethereum contract using solidity? { address1 => [struct1, struct2, struct3, struct4, struct5], address2 => [struct1, struct2, ...
6
votes
1answer
2k views

Is refunded gas for “freed” storage given to the contract, the “allocator”, or the “deleter”?

Is refunded gas for "freed" storage given to the contract, the "allocator", or the "deleter"? Suppose a contract allocates some storage. This storage is paid for by the sender of the transaction that ...
6
votes
2answers
2k views

Email Notifications

Is it possible to add email notification triggers into a smart contract? Could you store a persons email within a contract and at a set date have it send them an email?
6
votes
1answer
2k views

Who can access private state variables?

I was reading solidity Docs and everything made sense until I got to this: What are external observers? Is it clients listening for events or is it anyone who has access to web3 api? For example, ...
5
votes
1answer
636 views

How does Codius differ from Ethereum?

Codius is one of smart contract platforms by Ripple which project is unfortunately suspended. What did they try to do with Codius? How does it differ from Ethereum?
5
votes
1answer
828 views

Compile contracts that call each other

I have two contracts, one is a Admin, other is subject. To keep things simple I am just including the functions that are invoked in the contracts relating to each other. contract Subject { uint ...
5
votes
1answer
7k views

Is it possible to send ether from contract address to my account address using the CloseChannel() function and what will be the Truffle command?

pragma solidity ^0.4.0; contract exchange { mapping (address => uint256) public balances; event PaymentDone(string s); function Channel( uint value) payable { balances[msg....
5
votes
3answers
6k views

Interface Function

I understand that the following function is used to link the ico contract to the token. Appreciate if someone could explain how to use the function, and exactly how it works. Thank you. /** * @title ...
5
votes
3answers
1k views

Would it be better to use `throw` instead of `return false`?

My goal is to carry out some simple function but the user should be aware if the call fails. An example simple function could be seen here. Instead of return false, I want to use throw. Would their ...
5
votes
1answer
1k views

How can we organize storage of a folder or object tree in Solidity?

Inspired by Garbage collection A hierarchical storage pattern of objects inside objects is a pretty common device. How could one organize such a thing and avoid problems with increasing gas cost at ...