A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [contract-design]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
18 views

Fire transaction from contract

I have a contract holding a mapping like this: mapping (address => User) users. How can I get the contract to automatically fire a transaction/event when a certain condition is met? For example, ...
0
votes
1answer
17 views

Listen to a solidity event from a smart contract function [duplicate]

I have the following event: event WaitingPlayer2(address indexed player2); Which I call through: function partecipateAsPlayer2(address player2) public{ emit WaitingPlayer2(player2); } Is ...
0
votes
1answer
26 views

Making contract compatible with newer solidity version

I have a simple ERC20 contract however it doesn't work with modern solidity compilers, Could anyone make my contract compatible with solidity newer than 0.5.16? Thanks. Here is the code, it only ...
0
votes
1answer
22 views

How to properly initialize nested storage array/struct?

contract Contract { struct A { int a; } struct B { A[] as; } mapping(address => B[]) bs; function addB(B memory b) { bs[msg.sender].push(...???...); } } I have nested hell of arrays and ...
0
votes
1answer
17 views

Storing name values off-chain in events and web3.js

Somewhere I read the advice to store name (title, geographical name, people name, etc.) value off-chain in events. But if a value is stored in an event, is there an efficient way to retrieve its ...
0
votes
2answers
33 views

Making contract compatible with newer solidity compiler

I have a simple timelock contract however it doesn't work with modern solidity compilers, Could anyone make my contract compatible with solidity newer than 0.5.16? Thanks. Here is the code, it only ...
0
votes
2answers
33 views

IP address and system details of msg.sender

Is it possible to log the IP address and various system details (meta data etc.) about a msg.sender who is sending a transaction to your smart contract?
0
votes
1answer
18 views

Automate token distribution?

How can I execute a function on a smart contract from a web-app backend? (Laravel / PHP) My smart contracts holds X tokens. In my MySQL database, users are owed X tokens. I have their wallet ...
0
votes
1answer
18 views

How can I find the result of a function using Events?

Consider the following basic solidity smart contract event BattleResult(string result,uint playerResult, uint enemyResult); mapping(address => uint)playerChoice; function setChoice(...
0
votes
2answers
28 views

Call an existing python code inside a solidity smart contract

I want to call some existing code (written in Python) inside my Ethereum smart contract (written in solidity). Is it possible to do that? if so, how can we do it?
0
votes
1answer
17 views

Storing Tokens In The Most Secure Way

What is the most secure way to store tokens, if you are to roll out an ICO or similar? I know there are many ways, i.e. sharding the private key but what is the best practice right now? If I assign ...
0
votes
1answer
34 views

VM error: revert.The called function should be payable if you send value and the value you send should be less than your current balance

There is already a similar question, but it doesn't help me. So I ask this question again and expect something useful information. Two contracts named AccessControl.sol and Judge.sol. I've removed ...
0
votes
1answer
11 views

arrays and structs for function arguments

A lot of contracts and libraries with functions that use arrays and structs for arguments. Structs can themselves include arrays, structs and mappings. For example: function doSomething(MyStruct ...
0
votes
1answer
8 views

Can you have an array of mappings? The mappings have an address key and a struct value

Can you have an array of mappings? I want to have mappings with addresses as keys and structs as the value. I want to store these addresses in an array and iterate through them. so far it looks like ...
0
votes
1answer
17 views

dApp storage (growth) concern

My dApp allows user to save their URL when purchasing each NFT token. The obvious design would define -- struct NFT { ... string url; } However, URLs can be long. To save gas for users, I ...
0
votes
1answer
26 views

General practice on updating contracts on a blockchain?

I have been searching around a lot but couldn't find the answer to this. My understanding is that one a Ethereum blockchain, there should be one/multiple types contracts. Once live, those contract ...
4
votes
4answers
103 views

Efficient Solidity storage pattern for a directional weighted graph

I would like my graph's nodes to each have a struct of data and 0 or more pointers to other nodes. It needs to be efficient for insertions of new nodes in between two existing nodes. Should I use ...
1
vote
3answers
76 views

Smart contract execution without making transaction on ethereum blockchain

If I as a user of a smart contract ,call a function which does a heavy computation but doesn't change anything except the function variables which live only during function execution and then thrown ...
1
vote
1answer
36 views

How is multiparty computation (MPC) possible using Ethereum?

MPC involves running calculations on numbers, perhaps from different parties, and sharing the result without anyone seeing the underlying data. Even the person operating the computer cannot access the ...
3
votes
2answers
30 views

Variable Names and Memory

Is there a cut-off where a variable name uses more memory? For instance: uint public priceOfEthYesterday9AMUSAET vs uint public pEth One is more descriptive, but if it's costing me gas I don't ...
2
votes
1answer
26 views

How dangerous is to use tx.origin to check if msg.sender is some address? (details below…)

Let's say: function transfer() public payable { require(tx.origin == 0xb2930B35844a230f00E51431aCAe96Fe543a0347); msg.sender.call.value(1 ether)(); } Ignore the address above I just copied it ...
1
vote
1answer
24 views

can a smart contract autonomously hold erc20 tokens or ETH?

I want to make a simple smart contract, but I don't know if smart contracts are capable of what I desire. Please tell me if they are: a user can send ETH (or any ERC20 token) to the smart contract ...
0
votes
1answer
18 views

Function Efficiency

Say I have a function that handles 4 cases via if statements. I could break that into 4 separate functions. The case for breaking it up is that each function call would use less gas. The case against ...
0
votes
1answer
21 views

Writing string to separate block in Ethereum

Is it possible to take input of a string from client side and using smart contract write that string data to a new block inside the Ethereum blockchain mainet or any testnet? Basically take in ...
0
votes
1answer
19 views

Transaction Timing Implications for Reentry Attacks

This is the classic reentry attack: function withdrawBalance() public { uint amountToWithdraw = userBalances[msg.sender]; (bool success, ) = msg.sender.call.value(amountToWithdraw)(""); ...
3
votes
1answer
19 views

Can I add an int32 to an int256?

I'm trying to reduce the storage size of my contracts by reducing the bytes required to store my int data types (among other things). Can I get the best practice for adding int256 and other smaller ...
1
vote
1answer
21 views

A Way Around Restricted Getters

Consider a getter function with a restriction on who can read it, like function getData() public view returns (uint x) { require(msg.sender = '0x123..123'); x = data; } This ...
0
votes
1answer
23 views

Storing code in contracts

I'm considering different designs to implement "configuration options" with Ethereum. The design should allow me to define arbitrary (= number and type) options, quick access to a list of options, ...
2
votes
1answer
27 views

Solidity. Find whether a key exists in a mapping. Then get its value

I have a simple mapping: mapping(address => string) professorsExam; How can I check if msg.sender is a key in this mapping, and if it is, get its value? If it isn't I should return something. ...
0
votes
1answer
37 views

What is the best way to verify the comments in the contract code?

I have a contract that I want to be legally binding in traditional courts. It assigns rights, and for this I need legalese in the comments to describe the process. What is the best way to make sure ...
0
votes
1answer
42 views

Solidity: Is there any way to store the start time of solidity code? now() function returns block.timestamp only

I wanted to get a start time of solidity code, so I used now() previous which only returns block.timestamp whenever the solidity got started. Is there any way to store or know the start time of ...
0
votes
0answers
27 views

How to build a P2P wager contract with Solidity

I am looking to build a contract with Solidity that will take wagers on a football game between a bunch of friends. Each user should be able to place a bet on either team, with each bet to be added to ...
2
votes
2answers
34 views

loop though all the members of a map

I need to loop though all of the members of a map and change their property (which is a struct). the way i'm doing this is when adding a member to the map object also save it's address inside an ...
1
vote
3answers
52 views

How do you implement a front-end contract with back-end functionality in Solidity?

How do you create a front end contract that calls a back end with the idea of being able to upgrade or change the back end contracts without having to redeploy the front end contracts?
0
votes
3answers
29 views

Emitting Transfer Event even when there is no actual transfer

I am new to smart contracts and trying to understand it so that i can detect Ether transfers done to my user via Smart Contract. I know I can find the event emitted from topics[]. But for those ...
1
vote
1answer
12 views

Many-2-Many ERC721 Pattern?

I'm looking to build a smart contract with a function which is able to generate a unique and limited amount of ERC721 tokens based on an input string. I also want to be able to look up all the tokens ...
0
votes
2answers
52 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
18 views

How to substitute attributes instead of roles in access control coding for solidity?

Say, the role-based access control consists of two roles. But if I want to replace the roles to maybe location and time, how to go about it?
0
votes
0answers
19 views

Can a dapp/smart contract execute a transaction based on a private github file modification?

Scenario Suppose someone promises to deliver code to a private repository, that person is so sure they will, that they even said: "here is x eth, if I don't deliver in time, send the x eth to a ...
1
vote
1answer
18 views

Two calls to a contract: input of the first can only be revealed after the second call

I see that there are no parallel execution in EVM. The problem I am trying to solve is the following: I have a contract which takes the input of two parties -- say users A and B. The result of the ...
0
votes
2answers
42 views

How to get the result by parsing the log after executing the contract? How can I get the execution result?

How to get the result by parsing the log after executing the contract? How can I get the execution result ?
0
votes
1answer
29 views

Desired Revert if Condition Is True [closed]

What is the best way to revert inside a function if a particular condition is true? Sometimes safeguarding with require statements is not enough, i.e. uint256 constant public OFFER_LIMIT = 500 ...
0
votes
1answer
28 views

Memory Utilization Pattern Solidity?

I was wondering what is the most efficient way (and why), to use variables in memory for function calls with regards to A and B? A) Like this: function checkBalance() public view returns (uint256) ...
1
vote
1answer
39 views

Add Number to Item in all Struct Members

I have a struct where I want to increment an item across all struct members. For example, say there is a struct 'Contract', and new customers get their own bytes32 ID, which points to their own struct:...
0
votes
1answer
19 views

Need to enumerate keys of a mapping [duplicate]

I have a directed multigraph of courts "trusting" each other: struct TrustedCourt { uint256 courtId; mapping (uint256 => uint256) limits; // intercourt token => amount } ...
2
votes
2answers
58 views

How to generate a new token for ERC1155?

Developing an ERC1155 contract, how to generate an address for a new token? I need to create an API function like function createToken() returns (address). How? Should I just use an incrementing-by-...
0
votes
0answers
12 views

Why are there non-batch transfers in ERC-1155?

Why are there non-batch transfers in ERC-1155? Why not the API only for batch transfers? It would make contract codes shorter and thus simplified contract development and saved gas.
0
votes
0answers
9 views

Where to specify the spent limit?

I am creating a contract representing a court. A court can add an arbitrary amount of crypto to any account of its choice. (This is what a court is intended for.) It looks reasonable to assign a ...
0
votes
0answers
17 views

What is operator approval in context of ERC-1155?

https://github.com/enjin/erc-1155/blob/master/contracts/ERC1155.sol says something about "operator approval". What is an operator and what is operator approval?
0
votes
2answers
22 views

One or multiple owners?

My contract is controlled by owner(s) who can decide to discharge the money from it. The owner also can assign another owner, set spending limits, etc. Should the contract have one or several owners? ...