Questions tagged [contract-design]

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

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

Storing a monero address in smart contracts?

Assuming I would have to store Monero addresses or any cryptonote based coins addresses in a smart contract, would there be any issues? Consider that those addresses are as long as this random ...
5
votes
2answers
34 views

Pros and Cons of smart contract upgradable patterns

There have been quite many arguments around how to achieve smart contract updates like Upgradeable smart contracts. I feel Proxycontract with Delegate-call is currently the most famous one. But aside ...
-1
votes
0answers
38 views

Update a non-upgradable ERC721 contract [duplicate]

I'm trying to add some extensions to the ERC721 token standard. Usually, contracts should be desgined to be upgradable before deployment. The problem is that the contract is already deployed and the ...
-1
votes
0answers
18 views

How to select a wallet address by the token number he owns?

I need to allocate a winner among the token holders. I want to keep the concept that the more tokens someone buys the more chance there will be that he will be the winner. now lets say 960 tokens ...
0
votes
1answer
16 views

How can I use Ethereum smart contracts with another crypto currency?

I am learning/playing around with some concepts of the blockchain, smart contracts and Ethereum. I have created my own "toy" cryptocurency ("myCoin") by forking a coin using the CryptoNote algo. I ...
0
votes
1answer
24 views

Are there any good ways to express conditional ownership on ERC20 or ERC721 tokens?

I'm currently looking for any good ways to express conditional ownership on tokens. I look into approve function of both ERC20/ERC721 but, it seems that function may be disapproved by the owner and ...
0
votes
0answers
36 views

How to print the value of a Struct ?(mapping)

If the set function receives two inputs 1.["0xca35b7d915458ef540ade6068dfe2f44e8fa733c",50,"ROC","park"] 2.["0x14723a09acff6d2a60dcdf7aa4aff308fddc160c",60,"AU","school"] How do I display the ...
0
votes
0answers
18 views

Is there any for a contract A to directly read the value of another contract B , while B doesn't necessarily have any getter functions

The following codes is a function of contract B, how can a contract A get these values such as balance[from], balance[to], balance[msg.sender] as efficiently and directly as possible in contract B ...
0
votes
2answers
41 views

Am I Generating Random Numbers In A Non-Mallable Fashion?

Would this be a non-malleable way to generate numbers for my particular use case? Let me explain: I allow people to register for a lottery-type event. If a winning seed belongs to their ticket set, ...
1
vote
1answer
18 views

Are there identifiers for smart contracts?

Say I want to reference another smart contract in my smart contract. Do smart contracts have an identifier (like a number 0xjdjdjdjdjjddj etc.)? And if they don't, how would you reference a ...
0
votes
0answers
11 views

Random Number Generation, Appropriate case or no? [duplicate]

I'm building a lottery where I need to generate a list of random numbers. Basically, I have a group of people who will commit to a prize by staking a certain amount of tokens to their commitment - ...
1
vote
1answer
45 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 ...
1
vote
1answer
48 views

Web3 - Assign nonce to smart contract transact

I have a smart contract. I want to execute one of its state modifying functions. This is the code: const result = await smartContractObject.methods .addSomething(_valueToAdd) .send( { gas: '...
1
vote
0answers
35 views

Error: Operator << not compatible with types bytes1 and int_const 1 return b10 << 1;

I don't know how to correct the code of function 4 & 5. pragma solidity ^0.4.4; contract C { bytes1 b10 = 0x6c;// l-> 0110 1100 6c转换为10进制-》12*16^0+6*16^1=108 bytes1 b11 = 0x69; ...
0
votes
0answers
35 views

Error: Member “transfer” not found or not visible after argument-dependent lookup in address 0.4.4 [duplicate]

pragma solidity ^0.4.4; contract PayableWorld { function deposite () payable{ address dyw2 = 0x1De57DD112092D60F45c9e2045424003e6B2C75a; dyw2.transfer(msg.value); } how can i change the ...
0
votes
1answer
27 views

Solidity event not showing up from Web3.js

I'm trying to set up an event in Solidity and listen to it from Web3 but I keep getting a null response. Here's my code: The relevant part of the contract: event NewUser(string userid); function ...
0
votes
1answer
40 views

ERC20 - Approve & TransferFrom not working

The getTokenBalance function seems to retrieve data from the ERC20 contract just fine so I don't think there is an issue with how I'm using the interface. Additionally, I also tested out separating ...
0
votes
0answers
9 views

DigixDAO smart contract functionality/pattern

Can someone explain the usage of initialisation functionality and _resolver arguments in the various constructors of digixdao? i.e. following contract What is a resolver and isn't the job of a ...
1
vote
1answer
37 views

How to get timestamp of an event log in emitted event from smart contract

I want to get the timestamp of an event. How can I get time of event fired, if the event data does not contain any time value?
0
votes
1answer
12 views

interface function declarations to be used internally

Is it possible to use externally declared interface functions internally in a smart contract? i.e. say contract A inherits interface A, would contract A be able to implement the functions from ...
0
votes
1answer
25 views

Inheritance and contract creation

If I modularise a contract into two contracts, and inherit one of them instead using a monolithic approach, will the deployment costs be larger with two contracts or is the cost the same as with the ...
0
votes
0answers
16 views

Contract Design Patterns | Should I use some sort of factory pattern?

I have 3 structs which are nested into each other i.e. struct A <- struct B <-- struct C All 3 structs belong to their own contracts (contract A, contract B, contract C) and each contract has ...
0
votes
0answers
10 views

when to create a library contract

when should one consider creating library instead of a contract? Would it make sense to create a library if all it does is calculations or reporting read values?
0
votes
0answers
21 views

Best Practices Of Building A DAO Contract Structure Tree

When building a DAO of interconnected smart contracts on Ethereum, what is the best way to organise the contract structure? More specifically, are there any particular design pattern(s) like MVC in ...
3
votes
1answer
36 views

approve-transferfrom pattern between contracts

What is the general process-flow of approving contract a to spend tokens on behalf of contract b and how would a sufficient function implementation look like which successfully achieves this? For ...
0
votes
1answer
29 views

How to authorize multiple contracts issue the same ERC20 token?

I have a physical product to sell. I want to have a digital asset representing each unit of my physical asset. I have created an ERC20 token contract and each token represents a unique instance of the ...
0
votes
0answers
22 views

Interface restrictions

Why are interfaces restricted to enums, events, structs and functions? Why are they restricted from containing state variable declarations if they can contain structs?
0
votes
0answers
13 views

when to use byte32 -> string conversion in events, functions etc

When is it a good practice to use string conversion from bytes32? i.e. in events, functions and similar. What does doing so bring in terms of cons to gas costs?
2
votes
0answers
18 views

Name Styling Best Practices Internal/External variables/functions etc

The solidity docs clearly specify how to style function order, types etc. However, are there an appropriate way to also separate between internal/external variables, functions etc. I see some people ...
0
votes
2answers
25 views

Fetching stored values for use in function logic

Are there any benefits from fetching stored data into other functions by calling a function to call a private variable, instead of calling the private variable directly? What is best practices? ...
0
votes
3answers
22 views

Struct creates instances with zero values for all of it properties instead of using function arguments

Inside my smart contract I have a struct type NotaryEntry and a function addNotaryEntry which creates an instance of the struct and add to a mapping, I do pass the right values to the function but the ...
0
votes
1answer
19 views

How to request tokens from msg.sender within contract function

transferring ethereum from the user of your smart contract is simple enough, you simply use msg.value and can use this within your contract's functions. But doing the same thing with tokens is a bit ...
1
vote
2answers
34 views

Who is msg.sender in a nested call chain?

I read about who is msg.sender when calling a contract from a contract, but who is msg.sender when calling a contract from a contract that calls another contract and so on and so forth?
1
vote
0answers
30 views

how can i translate the ethers.js “getSigner” utility to web3?

I have a web3 object but I'm working off an example that uses ethersProvider.getSigner(). Is there an equivalent (or mostly equivalent) in the web3 library? For reference, the ethersProvider is ...
0
votes
1answer
23 views

Adding the delta to a token transfer

Let's say I have 5 contributors to a pool of a smart contract. They all contributed 1 ether. The smart contract lost 2 ether, and now I want to transfer back the remaining 3 ether to the 5 ...
0
votes
1answer
21 views

Mappings inside functions to filter query

I have a struct and several boolean mappings that are used to keep track of struct's properties struct Animal { string species; bytes32 ID; } mapping (bytes32 => Animal) public Animals; ...
0
votes
1answer
18 views

Tallying Majority Consensus From Nested Struct

How do I tally the votes of a nested struct to find out majority consensus? as an example, if we have following scenario below; I want to create a function which allows me to calculate whether ...
0
votes
1answer
26 views

Initialising Empty Arrays & Structs In Struct-based Storage Graph Structures?

How do I initialise empty arrays and structs in nested structs data structures? contract NewBook { struct ReviewerData { string name, uint industryXP // ...
1
vote
1answer
39 views

Updating an instance of an already stored struct?

How can I update/change the values of a stored struct instance? as an example: Let's say I've already deployed a chapter with the content written in a particular color. Later it turns out that I ...
0
votes
1answer
18 views

Returning an array of inner structs of a struct

How can I return an array of child structs of a parent struct? as an example: After pushing multiple chapters into the parent struct, how can I retrieve all the child structs as an array (or ...
0
votes
1answer
33 views

contract reading array from other contract

There are two contracts in my project: admin groups voting Admin groups contain mapping(uint => address[]) internal m_Admins For example [1][0] = admin #1 with level 1 [9][0] = admin #2 with ...
0
votes
1answer
31 views

Pushing A Struct Instance Into An Struct Array Of A Different Struct Mapping

How can I push a struct instance into a mapping which contains a distinct struct which contains a struct array of the attempted struct instance type? Example: contract NewBook { struct ...
0
votes
1answer
23 views

Return an array of structs using events?

I wan’t my function to spit out an array of structs. I know this is not straightforwardly possible. What is the best way for me to proceed? Should I loop through my array in my function and trigger ...
0
votes
1answer
51 views

Mapping Multiple Struct Instances To One Address

How can I map multiple struct instances to one user without overriding the previous instance? I want to retrieve both instances through one mapping query. Should I use a multi-dimensional array here ...
1
vote
1answer
26 views

What is the benefit of leaving data in the stroage area instead of the log?

I did not write English well and used a translator. sorry :3 I would like to know the benefit of leaving data in the storage area rather than using the event log. I know gas consumption has less log....
1
vote
1answer
34 views

Random Group Generation From Array

How can I form a random group of 5 people from an array of 100 people?
1
vote
1answer
22 views

Does the 10,000 refund apply to booleans too?

I understand from this thread that you're refunded up to 10,000 gas when setting a value to 0. Does this also apply to boolean values? That is, going from true to false?
0
votes
2answers
23 views

Smart Contract Interfacing - Best Practices

what is a general rule of thumb for creating interfaces? Why would I want an interface i.e. IAugur.sol instead of the entire Augur.sol file? Can someone shed light on interface best practices and pros/...
0
votes
1answer
21 views

How did cryotokitties create the image of the cats?

For cryptoKitties, the images of the cats are based on gene, for example, color, curve type etc. and the image of the cat will be created, how does the image created, it is by programming running ...
0
votes
1answer
26 views

Commit-Reveal Sequence Design

Let's cook up a scenario to ease understanding: We have a group of 5 people (addresses) who must vote on a question. The people can only vote True or False i.e. a boolean. The result of the vote ...