Questions tagged [solidity]

Solidity is a contract-oriented, high-level language whose syntax is similar to that of JavaScript and it is designed for writing smart contracts in Ethereum to run on the EVM. Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.

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

Passing structures between contracts with ABIEncoderV2 [closed]

Hello I am having problems passing accessing the structure Rental in my secound contract can some one help? contract RentalCompleting{ struct Rental { uint256 stratingDate; uint256 endingDate;...
0
votes
0answers
18 views

Inputs to Ethereum Solidity smart contract changing between invocation and execution

In this paper on smart contract blockchain programming paradigms the authors note that it is impossible to know in advance the inputs to a function in Solidity. This is because even if the input ...
1
vote
0answers
35 views

Transfer ERC20 via onother smart contract (call transfer as delegate)

I want to deposit erc20 tokens to a smart contract. But when I just send it to he address, I can't handle the deposit. So I tried to use the delegatecall function to do the transfer. Basically I ...
-1
votes
0answers
22 views

Can someone help me out with my Solidity code?

I'm trying to write a life insurance smart contract. My nested mapping of the beneficiaries compiles an error (undeclared identifier) and I really do not know how to divide the policy cash value and ...
0
votes
1answer
16 views

DeclarationError: Uninitialized storage pointer. Struct error when running truffle tests

I've seen other similar questions but they don't explain why this error happens and/or they are case specific questions. So, I have this code: pragma solidity >=0.4.22 <0.7.0; contract ...
1
vote
1answer
24 views

What's the purpose of the following code in the program?

I was following a tutorial on building a simple Solidity program for Ethereum transactions between a smart contract and account. However, I didn't understand the following code:- balanceReceived[msg....
0
votes
0answers
19 views

Auction project in Solidity: Why do I get “VM error: invalid opcode” for this code?

I am trying to do an Auction project and this part is bugging me. I can't figure out what is the problem that's causing the following error message: "VM error: invalid opcode.". Even if I do ...
0
votes
1answer
16 views

Truffle cant deploy contract with reverting constructor

I'm developing a dapp with the truffle suite and now I'm running into a problem. Everything is working locally in the ganache instance. My contract should disallow direct payments to the contract, so ...
0
votes
0answers
32 views

Deliver a dapp to a client, how to set as owner?

So, as a freelancer that wants to make a smart contract for a client, how do you set such client as the owner of the contract? Would it be setting the owner variable to the eth address of the client, ...
0
votes
0answers
23 views

public token swap contract

i want to create an erc20 token swap contract for a crowdsale im building right now. and i dont want to accept ether, i prefer USDT. i found a swap contract example on the internet but it always asks ...
0
votes
0answers
18 views

Switching addresses in Remix

I am creating contracts similar to VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if but combined with the restricting ...
1
vote
0answers
14 views

Filter past events with condition

Is it possible to filter past events with a boolean condition? For example I have the following event: event ExampleEvent(uint256 exampleNumber); In my js code I can filter these events with the == ...
0
votes
1answer
24 views

call a contract function which creates a new contract in web3.js makes an error VM Exception while processing transaction: revert

At first I'm developing with truffle v5.1.34, Node v10.16.0, Web3 v1.2.4 To make it simple, I have a Two contracts, DApp and User What i'm doing is call a DApp contract function which creates a new ...
1
vote
1answer
51 views

Getting stock market data from API or other means?

I'm trying to make a contract that interacts with a market price or a market out come : e.g APPL drops below X or NFLX > Y ... Is it possible in Solidity to call an external API during this ...
1
vote
1answer
19 views

Array of mapping

I would like an array of mappings, is this possible? mapping (address >= value) sentValue; sentValue[] public sentValues; I want to record amounts sent by address, and I want each send event to ...
0
votes
1answer
27 views

cannot transfer token from EOA account to a contract from function

i was making a contract for staking where user transfer its token to a contract and i will give him interest but i got stuck to this problem i have been searching for 3-4 days but for it is not ...
0
votes
1answer
22 views

Access Tuples elements

I have the following tuple: ( , , uint256 standardDepositAmount, , ) I need to use the standardDepositAmount in a require, like: require(standardDepositAmount == something) how can i do that?
0
votes
1answer
25 views

What is the proper way to store timestamp in blockchain?

I am trying to store the timestamp in the blockchain using block.timestamp or now. But that keeps throwing warning as Use of "block.timestamp": "block.timestamp" can be influenced ...
1
vote
1answer
19 views

DApp Development- how to update dapp and keep existing data

Compare to web application that separate the application and database, we can update the application and keep the existing data. Could you suggest me how to update dapp and keep the existing data?
1
vote
1answer
39 views

Building a recursive smart contract — is it possible?

I would like to create a sort of tree type hierarchy of contracts. Think of it like a multi-level-marketing scheme -- the person at the top will receive X. For each of the k people he recruits he ...
0
votes
1answer
22 views

How to make this interact with metamask

I've been trying to make my contract be callable by metamask (so a popup will occur telling the user to confirm) but it does not seem to work, heres what I have come up with so far. Can anyone give me ...
1
vote
0answers
25 views

How to update multiple values in a mapping without a loop?

if you have a mapping like: mapping (uint => bool) owned; How would you go through and update 1000 items in that mapping to set them all to true? Without using a loop due to gas prices. Is there a ...
1
vote
1answer
21 views

How does array.length— work?

I'm having trouble understanding why people call array.length-- after deleting an element in an array (as seen in this answer and many others). Why is there need for doing so? When is the length of ...
0
votes
1answer
21 views

Retrieve the return value from a non-constant function [duplicate]

Recently, I was reading a paper in which the writers stated that "In the Ethereum smart contract, the return value of the nonconstant function can only be obtained through logs event." ...
0
votes
0answers
20 views

Please look over my contract for re-entrancy

I know the random number generator isn't secure and is susceptible to manipulation from miners and any advice on the method to generate random numbers will be appreciated. However, the reason I'm ...
0
votes
1answer
19 views

Call few contract methods from another contract consistently

Can I call a few contract methods from another contract consistently in one block? The order of methods calls is important! if (contract.method1.value(msg.value)()) { contract.method2(someValue); }
0
votes
1answer
25 views

ipfs.add is not working

I am trying to upload my file to IPFS and save its hash to my Ethereum contract but neither ipfs.add nor ipfs.files.add is working for me... I have tried usin for loop i.e. for await (const result of ...
0
votes
1answer
30 views

UnimplementedFeatureError: Copying of type struct C.Friends memory[] memory to storage not yet supported

I'm always getting this error: UnimplementedFeatureError: Copying of type struct C.Friends memory[] memory to storage not yet supported. I don't know what is wrong and how to fix it. Can someone help ...
0
votes
1answer
35 views

How to set values for Solidity contract state variables from JavaScript front-end?

I am trying to set values to the following contract public state variables from a frontend javascript code. But it seems not working. Contract public state variables: // Current state of the auction. ...
0
votes
1answer
18 views

How can a Smart Contract pull an amount of Ether equal to its own balance from an External Account?

I'm writing a 2 Player Game. Rules: Player 1 must place a bet (and send some ether to the contract). Then, Player 2 must match the bet placed by Player 1, and send the same exact amount of ether to ...
0
votes
1answer
12 views

How much Ether does a Smart Contract Address hold before a Payable Instantiation?

The following code always reverts to "Contract must be empty". But shouldn't address(this).balance == 0 if the contract hasn't even been instantiated yet? Maybe since the contract doesn't ...
0
votes
0answers
11 views

Exucution of a payable function does not transfer any value between accounts when executing event on Ganache

I have created an smart contract that sends value from one account to another when calling the following function: function buyEnergy(uint _sellOrderId, address _sellerAddress ) public payable /*...
0
votes
1answer
21 views

Warning! Error encountered during contract execution [Reverted] web3

When calling from Remix IDE, it executes successfully. But when calling from web3 v1.2.9, it gives the above error. Here is the contract : https://ropsten.etherscan.io/address/...
0
votes
1answer
22 views

Issue with dynamic matrices in solidity

I have a matrix in solidity like that string x[][] I'm trying to write functions to return rows and colums The following code works well: // SPDX-License-Identifier: unlicensed pragma solidity ^0.6.0; ...
0
votes
1answer
27 views

How to call a method of another contract with given value?

How to call a method in another contract with given value? contract A { function f(int256 a, string b) { ... } } How to call A.f from another contract B with say 0.5 ETH value (if B was called with ...
1
vote
1answer
26 views

State Variables: What are they and how to create them?

I am new to ethereum and Solidity. I thought state variables are supposed to retain their value between calls. In the Solidity documentation, in the section State Variables, it says that state ...
1
vote
0answers
37 views

Alternative to ganache

can someone please tell me an alternative to Ganache? Tried installing ganache on my laptop and it's not supported. Ganache works on 64 bit computers and mine is 32bit. Is there a way I can go round ...
0
votes
1answer
39 views

Convert a string in scientific notation to a number

my smart contract uses an Oracle to retrieve the price. The price is returned as a string in scientific notation, for example, "3e-8". How I can convert this to number (uint)? The token has ...
0
votes
0answers
26 views

Insufficient funds for gas * price + value in Ropsten

I write API for smart contract but its shown error "Insufficient funds for gas * price + value"? My try I have increased my address balance but it's showing the same error. I have changed my ...
1
vote
2answers
30 views

Generating random number in Solidity without Chainlink

Hello I'm well aware there are plenty of threads around discussing different methods. Just curious and wanted to ask directly here because feel like the situation might be different. Essentially I'm ...
0
votes
0answers
28 views

How can know which is library's bytecode?

When I compile solidity file that has more then two contracts, Solc gives me some binaries. That binaries include bytecode of library. How can I know which one is library's bytecode if I don't have ...
1
vote
1answer
125 views

Is Solidity being replaced as the de facto standard for smart contract development?

Is Solidity being replaced by languages such as Rust or other programming languages for smart contract development?
0
votes
1answer
26 views

Which method is efficient to log data in blockchain? Send an event via smart contract or send data in a transaction without value?

I want to log data in Ethereum block-chain. It is obvious that we can create a smart contract that emits events and retrieve data from it. But is sending a transaction with data but no ETH value (just ...
0
votes
1answer
23 views

Error when retrieving the instance of a deployed contract

I have developed a EnergyExchange DApp in the Ganache local network with React that consist of one main contract "EnergyExchange". This main contract has a function to deploy new Agent ...
0
votes
1answer
13 views

Error when calling a get function from a deployed contract instance

I have developed a EnergyExchange DApp in the Ganache local network with React that consist of one main contract "EnergyExchange". This main contract has a function to deploy new Agent ...
0
votes
0answers
32 views

When to use “memory” and “storage” keyword in solidity 0.6.0?

From what I've learned and noticed. Please add more point and rectify me if I'm wrong. Use of memory keyword 1)When initialising/declaring Struct, Array , and mapping. 2)In the parameters of functions ...
0
votes
1answer
20 views

Error in code Expected pragma, import directive or contract/interface/library definitio

I am getting the below error when i compile the below code. Using remix compiler version 0.5.11 ****browser/TodoList.sol:7:2: ParserError: Expected pragma, import directive or contract/interface/...
1
vote
1answer
39 views

what replaces assigning array.length to 0 for clearing it [duplicate]

I'm trying to follow the tutorial here and there's a line where an address array players has this done players.length = 0 which issues this error: member length is read-only and cannot be used to ...
0
votes
1answer
28 views

How to save the contract instance on a mapping in solidity?

I have created an EnergyExchange contract in my React app.js that it is deployed in the network. Inside the EnergyExchange contract there is a function to create Agent contracts. What I am trying to ...
0
votes
1answer
15 views

What are variables defined as functions in the abi?

I was experimenting with this simple contract on a test network: contract HelloWorld { string public message; constructor(string memory initMessage) public { message = initMessage; } ...