Questions tagged [contract-design]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
15 views

Solidity re-entrancy attacks and how to guard against them

I'm trying to understand re-entrancy attacks. Is tip1() below at risk of a re-entrancy attack (if the fallback function of the miner's contract invokes tip1() itself)? And if so, is tip2() safe? ...
0
votes
1answer
20 views

Can you use smart contract 'instances' rather than deploying each new contract?

My apologies in advance for this noob question, I think a scenario might be the best way to ask: I have a simple escrow smart contract that facilitates the buying of products. For simplicity sake, the ...
0
votes
0answers
11 views

Is using blockhash a good source of randomness on PoS blockchains with a lot of blocks mined in a short period of time?

I am trying to make a casino-like game using a smart contract and employing only on-chain data. I understand that on a blockchain like Ethereum a malicious miner can cheat the system by withholding ...
0
votes
1answer
15 views

Is it possible to upgrade an NFT instead of having to burn the previous and creating a new one?

I wanted to know if this was possible. For example, if I own 1 NFT of Charmander and I then "mint" an evolve, is there a way to turn the first Charmander into Charmeleon without creating a ...
3
votes
2answers
77 views

Why do we grant access to our funds instead of just sending them to the smart contract?

In DeFi I have seen that users are prompted to give access to their funds. Why not just send those funds to the smart contract instead? What is the advantage of this design?
0
votes
1answer
15 views

Storing struct with mapping inside of mapping

I have the following structures defined in my smart contract: mapping(bytes4 => Question) private questions; struct Question { bytes8[] answers; mapping(bytes32 => bool) answerers; } ...
0
votes
0answers
16 views

Let users add data to smart contract anonymously: Possible?

To learn more about smart contracts, I thought I could start by building a super simple dApp, which only does two things: Allow users (addresses) to share some random info to the contract (In my case ...
0
votes
0answers
11 views

Best practices for functions with highly variable gas cost

I'm developing a Dapp with a function (let's just call functionA) that has potentially significantly different gas cost between invocations. This is due to the need for costly extra computation when ...
0
votes
0answers
24 views

Can an external source be used in place of a proxy contract?

The recommended way to create updatable contracts is to create a proxy contract which then calls an origial contract. I haven’t worked with proxy contracts yet, but I’ve seen the code and it appeared ...
0
votes
1answer
15 views

Why do we need to use private variable getters inside the same contract?

I recently read a smart contract from Openzepplin with the following code in it uint256 private certainAmount; function getCertainAmount() public returns (uint256){ return ...
1
vote
0answers
17 views

Does a proxy contract need to declare state variables?

There is no variable declaration in the proxy contract. Does the returned data from the delegate call auto-generate the variables for the proxy contract? contract Logic { uint256 varA; ...
0
votes
0answers
10 views

Typical flow for generating large set of unique ERC-721 metadata and setting tokenURI

First of all, I have searched around in previous posts and haven't found an answer to this so apologies in advance if this is a duplicate. I am minting a collection of NFTs via ERC-721 and have the ...
0
votes
0answers
7 views

What are the benefits of using hard coded gas values in smart contract?

I was reading the docs of Arbitrum and found this hard coded gas values should be adjusted (or better yet, removed entirely if possible (it's probably possible; really now, why are you hard-coding a ...
1
vote
1answer
18 views

First Smart Contract: How to emit exact string data?

So I've written my first smart contract and deployed it onto the Ropsten test network, which is a simple program to write "hello world" into the data field when deployed. pragma solidity 0.8....
0
votes
0answers
3 views

Can you authenticate a process or an algorithm with a NFT?

In computer-generated-arts, can you authenticate the generating process or algorithm with a NFT, or only the resulting "work of arts" ? More generally, is it possible to authenticate a ...
0
votes
2answers
36 views

Ownable in upgradeable contracts

I'm trying to get my head around the Ownable role in Upgradeable contracts in open zeppelin. It seems there have been a lot of updates recently and most tutorials and answers are therefore outdated. I'...
1
vote
1answer
31 views

Efficiently Accessing Mappings

I'm working on keeping track of data via a struct stored in a mapping. mapping(uint256 => Session); Here is the Session struct: struct Session { // UID uint256 id; // Timestamp ...
0
votes
0answers
12 views

Name has to refer to a struct, enum or contract when compiling on remix

This is betting smart contract, the issue is the user/address need to bet on different matches. The smart contract design only on one mapping value. Full source code:https://github.com/laronlineworld/...
0
votes
1answer
21 views

How can I validate transaction?

I have question related to transactions. Is is possible to verify transaction by sender and receiver. For example user A want to send money to user B. User A create transaction, digitaly signed. ...
0
votes
0answers
22 views

How to set the ether price for a tokenID with ERC1155?

I'm creating an NFT streaming marketplace for musicians and I think ERC1155 standard contract will work for my use case. Assuming I am the owner and minter of the whole system, and I am minting on ...
0
votes
1answer
47 views

TypeError: Indexed expression has to be a type, mapping or array (is function (uint16) returns (uint256))?

Full source:https://github.com/laronlineworld/bettingMatch/blob/main/bettingMatch.sol This is a Betting Smart Contract, trying to create a mapping structure that user/wallet_address can bet on ...
0
votes
0answers
39 views

How to apply mapping? Betting on multiple matches using 1 address?

how to change the data structure of playerInfo so that instead of one value for playerInfo[msg.sender].matchSelected, it would have a mapping of values. Also, you need to include resultSelected in the ...
0
votes
0answers
58 views

Creating Structure for mapping of data inside mapping? [duplicate]

you would need to change the data structure of playerInfo so that instead of one value for playerInfo[msg.sender].matchSelected, it would have a mapping of values. Also, you need to include ...
0
votes
0answers
13 views

transfer from one contract to another

// ContractA function nice(address to) public payable { require(_to.send(_value), ERROR_SEND_REVERTED); } I also have a contractB which was deployed with EIP-1167. Now, The problem is that when ...
0
votes
1answer
39 views

how to add closing and opening function bet per match in soldity?

source code:https://github.com/laronlineworld/bettingMatch/blob/main/bettingMatch.sol How to open and close bet per match function bet(uint16 _matchSelected, uint16 _resultSelected) public payable { ...
0
votes
2answers
24 views

Can someone help me to fix the betting, I can't bet on other game match_id once I bet on a match

Thi is the full smart contract:https://github.com/laronlineworld/betMatch/blob/main/betMatch.sol This is betting contract, when betting on id_1, the same address can't bet on id_2. I'm using Game ...
0
votes
1answer
29 views

Real World Application using Smart Contracts

I am trying to build an application using Smart Contracts. I am only able to find tutorials that introduce Solidity and smart contracts (which are helpful though). But I am unable to find a complete ...
0
votes
1answer
45 views

{ "code": -32000, "message": "invalid opcode: opcode 0xfe not defined" }

When distributing prize, this error will show:{ "code": -32000, "message": "invalid opcode: opcode 0xfe not defined" } full code here:https://github.com/laronlineworld/...
0
votes
1answer
15 views

Minting parent tokens from child contract

Is it possible to mint ERC20 tokens that are created in a parent contract, from a child contract? If so how is it implemented? Thank you in advance!
0
votes
0answers
10 views

Is it possible to create a vesting contract for NFT?

Creating vesting contract for NFT(erc721)? We have token vesting smart contract, but how about NFT? Can it be vested on a smart contract?
0
votes
0answers
130 views

How to transfer USDT out of a smart contract? [duplicate]

I'm having a trouble trying to solve this task: I created a very simple smart contract that should call a function in the external smart contract and transfer tokens. Here's my contract code: pragma ...
0
votes
1answer
38 views

Betting Smart contract using Token (Bep-20/erc20) instead of ether/bnb?

This is my betting contract using eth/bnb, how can I change eth/bnb to token as their betting payment https://github.com/laronlineworld/BettingCOD/blob/main/BettingCOD.sol Code for Betting function ...
0
votes
1answer
55 views

Lock multiple batches of ERC20 tokens for a certain amount of time

I need to build a smart contract where users can lock their ERC20 tokens for a fixed amount of time (same amount of time for all users, e.g. 1 year). Lets say a user locks 100 tokens and half a year ...
0
votes
0answers
17 views

{ "code": -32000, "message": "execution reverted" } For betting Reward distribution

function execution reverted if function is applying function distibuteRewards() onlyOwner public { require(bettingActive = false); bytes32 winningCandidate = candidateList[getWinner()]; /...
0
votes
0answers
20 views

Wierd exploit in auto-liquidity token

i dont know if this is a known exploit or not, but this caught my attention. It seems that address on mainnet is a contract (unverified of course) that takes advantage of a vulnerability somewhere ...
1
vote
1answer
22 views

I accidentally sent token to the currency contract

I accidentally sent token to the currency contract, is it possible to get the tokens back? Can any expert tell me if the contract has the function? what is the function? Contract: ...
2
votes
2answers
292 views

What is best to use - Private Key or Mnemonic?

Is there a best practice for which one to use? Many tutorials online take various approaches - the older ones seems to use mnemonic whereas the newer ones tends to utilize private key. I understand ...
0
votes
1answer
20 views

How to enter a uint256[] function input in java script?

I'm trying to interact with my smart contract using java script. My function uses an uint256[] input. In python the desired input would be input = [1,2] In java script I tried const arrayindex ...
0
votes
1answer
15 views

Recording gas usage at a specific point in execution

I apologize if it has already been asked here, but i'm currently building a limit orders contract and i'm trying to do something like that. function fullfillMaxOrders() public { while(gasConsumed <=...
0
votes
1answer
23 views

Can I interact with a smart-contract that's a variable inside another smart-contract?

I want to interact with a third party contract. I can interact with (third party) Smart Contract A. Inside Smart Contract A's code is import { contractb } from ".../ContractB.sol"; ...
0
votes
1answer
20 views

Is it common to add comission to the contract for the secondary market?

I looked at Cryptopunks contract and I don't see any royalty going to Larva Labs. Is it normal to add a comission back to me for my generative art project? I noticed some projects take a set price ...
0
votes
0answers
16 views

Using the return value of a contract function in another function

I have a smart contract A with a public function a1 that can be called by anyone and this public function will return a uint value based on another public function named a2 inside the same contract A. ...
0
votes
1answer
22 views

How to change the bet of ether into bep-20 token?

The link of Betting Contract:https://github.com/laronlineworld/Voting-Betting-Smart-Contract/blob/main/Voting-Betting-Smart-Contract.sol How to change the bet ether into token(BEP20) function ...
0
votes
1answer
14 views

Is there a smart contract that rewards someone who has held a token for a certain amount of time with additional tokens?

Basically if someone holds a token for a given time "x" amount then they are rewarded extra tokens? Is there a smart contract that can do this or is it even possible? Thank you.
0
votes
1answer
18 views

Which section should be first? Upstream and downstream sections

Well... I have a problem of starting writing smart contract in with I don't know which part should be written first. For example we have a game. It has a hero and it has some functions like fighting ...
0
votes
1answer
43 views

Dynamically calling any other contract and function from contract

This gives a contract the same ability to interact with other contracts (with its address as msg.sender), as an externally-owned account, right? function call(address _contract, bytes calldata ...
1
vote
1answer
28 views

Is it possible to create a vault that will open itself after a countdown (dead man's switch) on blockchain?

I know I can put an encrypted data and a timer in the contract, but what about the key? People can't know the key. It must be only used when the countdown ends, automatically.
0
votes
1answer
98 views

How to return a storage array from a Solidity function?

I wrote a very simple smart-contract where I want to create an external function which returns as an output a storage array which contains the following items [0,2,4,6,8,10,12,14,16,18]: pragma ...
0
votes
1answer
29 views

Can I automatically forward transactions from a given address?

The challenge is to provably promise to transfer a transaction from address X to address Y. Basically, I need to be able to convince Y that if I get the money from X - it's going straight to Y. X is ...
0
votes
1answer
44 views

DeclarationError: Identifier already declared

I'm getting the below compile error message: DeclarationError: Identifier already declared. --> contracts/coffeeBase/SupplyChain.sol:9:1: | 9 | import "../coffeeAccessControl/ConsumerRole.sol&...

1
2 3 4 5
39