Questions tagged [contract-design]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
112 views

Transactions of ether between contracts

I am trying to figure out how transactions between contracts work and what you can and cannot do. I want to have a contract that makes some logical decision about who to pay when poked by another ...
5
votes
2answers
961 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?
1
vote
2answers
97 views

Random distribution of large amount of NFT

I'm an beginner in solidity, and with a teamate we have a project for an NFT contract. I have a contract with 5000 NFT limite (cards, and 20 specific card form a familily, each family and cards are ...
0
votes
1answer
11 views

Safe way to make a payable function that accepts a ERC20 Token in a contract that didn't create that Token

I have two contracts, contract A represents Token A, contract B is its own contract. I users to call a contract B function by paying Token A to contract B, as if they were using a payable function, ...
1
vote
1answer
12 views

Untitleded.sol:5:77: ParserError: Expected type name function sendmessage(string message) view public returns(string message, memory) { ^----^(i need)

I've seen the other StackExchange errors but it didn't help me. Untitleded.sol:5:77: ParserError: Expected type name function sendmessage(string message) view public returns(string message, memory) { ...
1
vote
1answer
55 views

Error Handling on Contract Calls to Other Contracts

I'm trying to call a function from another contract and need a way to accommodate errors. Say contract A has the method getBalance: function getBalance(address x) public view ...
2
votes
1answer
43 views

Bundling two assets in a contract and issuing shares for them

Say you are tasked with coding a smart contract with the following features: Users can deposit token A and receive liquidity shares in return. The contract starts selling token A for token B ...
13
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 ...
0
votes
1answer
11 views

array vs mapping in solidity: when to use one over the other?

When should you use array or mapping in solidity? Let's say I have multiple question questionnaire, with one question, and I want to store the responses of different people(address) in a smart ...
0
votes
1answer
14 views

Designing a smart contract that can buy (or bid) on an NFT on behalf of a user

I am a server-side developer who started learning solidity a few weeks ago. I am writing smart contracts for practice. Currently, I am stuck conceptually and need help from industry experts. Imagine a ...
1
vote
1answer
63 views

Filter topic across multiple contracts

Is there something I could add to my contract which allows my application to filter for all the deployed contracts which also included this topic/identifier? The only other option to manage this I ...
0
votes
1answer
22 views

How to send ether to an 'empty' contract

I have two smart contracts. A caller and a receiver. My caller code looks like so: // SPDX-License-Identifier: G.P.L 3.0 pragma solidity 0.8.3; contract Caller { event Response(bool success, ...
1
vote
3answers
75 views

Cost-effective way to calculate final user balance based on variable events

Apologies for the title. I'm not sure what would be a more descriptive way to name this question. Assume there is a contract which has 3 potential parties. Buyers, sellers and shareholders. Buyers/...
0
votes
1answer
15 views

When can you use this in a constructor?

I am going through the solidity docs and I have seen that: // Functions can // be accessed directly or through `this.f`, // but the latter provides an external view // to the function. ...
0
votes
1answer
10 views

Requiring a specific type of token in smart contract

Newbie here. For practice, I'm writing a smart contract where multiple users can pool funds. E.g. 3 users can contribute 100 DAI tokens to the contract. At the moment, the smart contract does nothing ...
0
votes
1answer
24 views

When is hashing used when creating a smart contract?

I was going through the solidity docs and in a contract example given I have seen keccak256 used. // Perform checks to determine if transferring a token to the // `OwnedToken` contract should proceed ...
0
votes
1answer
8 views

Why is it fine to reference a contract type but not use it to create a new contract?

I am going through the solidity docs and I have seen, in the code example given that: // `TokenCreator` is a contract type that is defined below. // It is fine to reference it as long as it is not ...
0
votes
0answers
4 views

tracking state changes via function calls that does not include event usage

Is it possible to track changes made to a smart contracts via its functions if the functions are not emitting events. I suppose if I know the function signature representation, then I should be able ...
0
votes
1answer
63 views

How to vaildate the structure of a smart contract?

I want to automatically verify the structure of a published smart contract. A smart contract should be valid if the smart contract matches a template. Only the storage can diverge between the template ...
0
votes
0answers
9 views

Using Solidity to write a contract that uses an existing token

I am trying to learn Solidity. I recently did this tutorial here: https://ethereumdev.io/transfers-and-approval-or-erc20-tokens-from-a-solidity-smart-contract/ I found it very informative. I was ...
0
votes
1answer
7 views

Semantic versioning in solidity

From the solidity docs I have read that: The version pragma is used as follows: pragma solidity ^0.5.2; A source file with the line above does not compile with a compiler earlier than version 0.5.2, ...
0
votes
2answers
73 views

How to limit number of tokens that can be transfered in a given timeframe?

How can one ensure that an ERC20 token holder can’t send/transfer/other more than X token in given period Y where Y could an hour, day, week, month etc. Would be better if this can be done without ...
1
vote
1answer
194 views

Private Ethereum Smart Contract API call to notify (without needing the external api response to update the state) without using Oraclize

In a Private Ethereum Smart Contract, can we do an external API call just to notify (without needing the external api response to update the state) without using Oraclize? Understand Oraclize is ...
0
votes
1answer
160 views

Function burnfrom error: gas required exceeds allowance or always failing transaction

I have created a contract using Remix. When I run the function burnFrom(), it shows: gas required exceeds allowance or always failing transaction. What am I doing wrong? function burnFrom(address ...
1
vote
1answer
66 views

Can a flash loan used to flash attack a smart contract?

I am new to flash loans. Let us say I have smart contract where people vote. Your voting power on this contract is based on how many token x you have. The votes are yes and no and the vote with more ...
0
votes
2answers
32 views

Call state modifying function in view function

Is it somehow possible to do something like this? contract Test { function test (bool isTransaction) public view { if (isTransaction) { foo(); } ... } ...
1
vote
1answer
68 views

Payable contract with multiple “options”?

I'm trying to create a contract that behaves differently based on the user's selection. I, however, have no idea how to let the user "select" the option. Currently I have a basic fallback function ...
0
votes
3answers
181 views

New temporary struct causing state variables to be overwritten

I'm running an experiment where I'm trying to create the following behavior: Service owner deploys Experiment1 to the blockchain and is recorded as the owner. Owner then adds a user address, a user-...
0
votes
1answer
103 views

Prevent Transfer of ERC20 token to contract address?

I want my ERC20 contract to be transferred to EOA addresses only and some specific contract address only. I don't want to lose my tokens by mistakenly transferring to a contract address that cannot ...
1
vote
0answers
11 views

how to decode/encode ipfs for contracts

It's known that IPFS can use 2 types of CID, v0 and v1. In my contract, I let users store bytes data parameter. They can store some simple text on it or even pass the ipfs hash. This question is about ...
1
vote
1answer
82 views

Solidity/Remix Error: The constructor should be payable if you send value enum change state

I'm using this (State Machine) design pattern in solidity and having an error when changing the state after executing the first function. Any hint? Thank you! Error: revert The transaction has been ...
0
votes
1answer
14 views

Problems on a simple contract

I am a new learner in solidity. My simple contract cannot compile in remix and I do not know how to fix the error in line 18 (the declaration of uploadStudent). The error is 'Data location can be ...
2
votes
2answers
116 views

To transfer tokens from owner address to an address, if latter address moves some other tokens to a given particular address

I am writing a contract for an ERC20 token (say ABC). Is it possible to airdrop some of these newly minted ABC tokens to those ERC20 addresses, every time, if they transfer a different token (named ...
1
vote
0answers
14 views

ERC1155 minter function

im working on a ERC1155 token. as you may know openzeppelin has a presetMinter for it, but i want to mint my token with more complex things. i see 3 methods to do it: 1- without using presetMinter ...
0
votes
1answer
22 views

Is every trade in a decentralised exchange a smart contract?

Is every trade in a decentralised exchange a new smart contract? How does exchanging work in decentralised exchanges?
0
votes
0answers
9 views

What are the advantages of selfdestruct-ing a smart contract?

I know this might be a subjective question but I am trying to understand why the ability to selfdistract a contract exists. What is the use of self distract? Are there any dapps using self distract as ...
0
votes
1answer
65 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
0answers
12 views

How can a contract interact with other chains?

Reading the Waifusion postmortem article this caught my eye: At the same time, we were made aware of multiple parties that were going to fork us as soon as we went live with a sale on BSC. This has ...
1
vote
1answer
17 views

Internal transactions totaling 100+ Ether flowing into a wallet

When you look at the wallet address below, it has a balance over 100 ETH but there are no inflows in the etherscan ledger to show where those funds came from https://etherscan.io/address/...
1
vote
1answer
19 views

Can a chain link node listen to ethereum smart contracts events?

Can a chain link node listen to ethereum smart contracts events? Let’s say I want to provide data to a node from a smart contract. Can a I link a chain link node and use a smart contract as an oracle?
1
vote
2answers
57 views

The correct approach to changing inherited variable content

What is the correct approach to change the content of an inherited variable? If contract A inherits contract B which has an variable b, and contract A is initialising the inherited variable b ...
0
votes
1answer
46 views

how to read a variable from an already deployed smartcontract without a predeclared getter function? [duplicate]

i want to read a variable from an existing contract to my own contract using smart contracts. (not js) i know there are methods to import smart contracts: import './OtherContract.sol' contract cont ...
0
votes
1answer
19 views

How to keep track of your smart contracts without a centralized server?

How to keep track of your smart contracts without a centralized server? Let’s say I have a dapp that creates smart contracts. Is there a way I can keep track of all the smart contracts my dapp has ...
3
votes
2answers
762 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
1answer
12 views

How this snippet is linking contracts? How each contract finds the other

I'm trying to understand how can two contracts be deployed and interact with each other, given that I don't have their addresses before deployment. I ended in this question and I don't understand the ...
7
votes
1answer
17k 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() { ...
0
votes
2answers
62 views

Is this contract correct?

Hi i write simple contract to test. Does he have any known mistakes or bugs? What would you change in it for the better? Thanks for answer. pragma solidity ^0.4.21; contract Lock { uint256 ...
6
votes
1answer
25 views

Does Solidity pre-compute the powers of two defined in the body of functions?

I'm using the powers of two in only one my contract functions, but I defined them at the top-level thinking that this way I would save gas at runtime. Is that necessary though? Can I do the following ...
0
votes
2answers
390 views

Is there a way to dynamically create a contract that points to a previous contract?

I would like to implement a tracking system .. where i track events between two parties who deliver an item between them .. then the receiver would deliver it to another person and so on... I would ...
0
votes
1answer
62 views

Multiple transfers, one smart contract

I have the following function in my contract: function AcceptOffer() public payable { if ( msg.sender != InstanceOwner ) { revert("You are not the owner of this ...

1
2 3 4 5
36