Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
2 views

Different events for revert types or one event and then on the client/backend figure the reason why it reverted from emitted data?

Let's say I have 3 conditions which can lead to revert(). which way should I handle it? 3 types of events or one event with extra parameters? 3 events types: if condition A: emit causeA(dataA1, ...
0
votes
1answer
8 views

Contracts interaction issue

I got stuck in making two contracts interact. The code for two contracts is as follows: Test1.sol pragma solidity ^0.5.8; contract Test1 { struct Car { string carCreationDate; ...
0
votes
0answers
6 views

Parity POA Smart Contract Method Always Fails

I have set up a private POA Network according to the tutorial from the parity homepage. I have two nodes running on localhost:8540 and localhost:8541. I have connected MetaMask to my first node and am ...
0
votes
1answer
21 views

Can anyone explain How smart contract gets validated?

Is there any validation process of smart contract's write operations ?
0
votes
0answers
8 views

solcx compile_files Key error

I am using python package py-solc-x for compiling the smart contract. os.path.abspath("D:/new.sol") Gives path where my test contract exits. 'D:\\new.sol' Then i use compile_files to compile the ...
0
votes
1answer
24 views

How to hash multiple values including array keccak256 Solidity v5.0.x and web3

How can I receive the same hash in solidity and web3? Multiple values where one is a multi dimensional array. Solidity v0.5.x: keccak256(abi.encodePacked(a, b, c, d)); Web3: web3.utils....
1
vote
2answers
23 views

Verify if an input is a hash

What is the best way to verify that a text I received in mu function is a valid hash? In other words, contains a specified length and is composed only by numbers and "a", "b", "c", "d", "e" or "f"?
0
votes
1answer
10 views

Gas requirement of function “testCompile.showString() high: infinite”

I have written simple function in remix. pragma solidity ^0.5.0; contract testCompile{ string myString = "Hello World"; function showString() public view returns (string memory){...
0
votes
0answers
28 views

Timestamp is giving wrong time in smart contract

Today is June 17. but when I execute my function and store the following arguments. WriterModel(owner,postID, _postContent, now); "now", It returns the July 20 timestamp. It perfectly working fine ...
0
votes
0answers
20 views

Function returns always with the same input even it is in the loop..TRUFFLE+ANGULAR 7+WEB3

One of the function in Contract: function getPostCounts(uint _postID)public view returns(PostCountsModel memory postCounts){ return postCountOperations[_postID]; } This is the calling ...
1
vote
0answers
28 views

exploiting keccak for random number generation?

Whenever a ticket will be purchased, a random number will be generated function _mightWin() internal { address _player = msg.sender; // players address uint256 ...
0
votes
1answer
29 views

Percentage calculation

I'm currently learning how to write smart contracts. While studying some code, I came across this line: ‭ uint256 a = value.ceil(basePercent); (with: uint256 public basePercent = 100;) Then one ...
0
votes
1answer
24 views

Value not pushing into array inside structure

pragma solidity ^0.5.0; contract Testing{ struct personalInfo { uint id; string[] colors; bool player; } mapping(uint=> ...
1
vote
0answers
17 views

How to upgrade this Crowdsale contract (from DappUniverse)

i'm trying to compile this code (from DappUniversity: https://github.com/dappuniversity/ico_irl/blob/master/contracts/DappTokenCrowdsale.sol) but with the new version of OpenZeppelin, that's use at ...
1
vote
1answer
39 views

Mapping with iterating uint as identifier - multiple transactions in the same block

I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue: pragma ...
0
votes
0answers
11 views

web3js batch execute method gives error

I have private/local network/chain setup. I'm building this with Nodejs-->expressjs. const contract = new web3.eth.Contract(abi, address); const batch = new web3.BatchRequest(); batch.add(contract....
0
votes
2answers
30 views

Save all customers who buy an item online

I am writing a contract where I am trying to save the account addresses of customers who buy an item online. I tried it with arrays but it did not work. Can anyone please suggest a way of doing this?
0
votes
1answer
16 views

TRUFFE MIGRATE: Saving migration to chain.Error: Error: Error: Returned error: VM Exception while processing transaction: invalid opcode

$ truffle migrate Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile. Starting migrations... ====================== > Network name: ...
0
votes
1answer
15 views

ERC20, how to calculate how many tokens for crowdsale?

If you look at this article, the total tokens for crowdsale is 100 tokens and defined in the code as uint256 public maxTokens = 100000000000000000000; how come 100000000000000000000 becomes 100 ...
0
votes
2answers
27 views

Instantiating a contract inside another contract on behalf of some address

I want to initialise an instance of a contract inside another contract on behalf of some address. e.g. I have contracts A and B contract A{ address owner; constructor() public{ ...
0
votes
0answers
18 views

problem with the task function in truffle development

I am doing the "TodoList" exercise and when I use truffle (development), I do not return the call with task, I get the following error: truffle (development)> todoList = await TodoList.deployed () ...
0
votes
1answer
18 views

Function to transfer tokens to a second address with fixed percentage

I'm trying to code a transfer function that automatically sends tokens to a second address taking a specific percentage from the original sent value. What I wrote: address public _ExtAddress; ...
0
votes
0answers
18 views

Split State Storage Contract

This is a follow-up question of Split Contract Design Pitfall Background: I have split my logic into two contracts A and B. A keeps the state and not ETH. All state change functions are only allowed ...
0
votes
3answers
35 views

Auction contract question - Ether lock

I have an auction contract, where bidders bid with Ether then me (owner) select which offer is most suitable and thus this bidder is contract winner. Once the winner is selected, I send him data as a ...
0
votes
0answers
9 views

Can't call contract function in Remix in Web3 provider mode, but it works in Javascript VM

A simple contract for addition, an error is reported when calling the function add in Web3 provider mode: "Gas estimation errored with the following message (see below). The transaction execution ...
0
votes
1answer
15 views

Problem understanding the owner assignment

Suppose I have 3 contracts, namely Owner, B and C: contract Owned { address public owner; constructor() public { owner = msg.sender; } modifier onlyOwner { require(...
0
votes
0answers
15 views

What are the specifications of Ethereum wallet smart contract?

I just want to know the must-have specs of an Ethereum ERC20 wallet contract. How can I make a wallet for normal users(Can just perform txns of their tokens.) and for high level(Can perform every ...
0
votes
1answer
19 views

How to call setter method of smart contract with web3 1.0.0

I don't know why but i'm not able to perform transaction with this code. please help me out i'm stuck. i just have to call setter method of my contract with some arguments. router.post("/set", async ...
0
votes
0answers
27 views

Why this error occurring when i running my dapp?

I create a dapp using Solidity,Web3Js,Javascript and Html with metamask i always getting this error when i am trying to submit my transition i am getting this error at c (inpage.js:1) at ...
0
votes
2answers
25 views

use the caller of the wrapper function to call the inner function

Suppose, I have 2 contracts A and B: contract A{ function someMethod() public{ // Something happens here } } And contract B containing its instance and its wrapper function ...
1
vote
1answer
40 views

Solidity Error:Running Out of Gas / selfdestruct problem

I've been going through 'Building Cryptocurrency and its ICO' by DappUniversity. I know many have questioned this issue and I've been through all the post but couldn't resolve it. The problem is self-...
0
votes
0answers
15 views

Web3js v0.20.7 - callback ls not a function

I'm facing issue of callback is not a function in web3js 0.20.7 when i call the method of sendRawTransaction to deploy smart contract with web3. When i used the same method just to call deployed ...
0
votes
1answer
15 views

what does that 'No state variables' restriction in Libraries?

I read some about Libraries restriction that 'No state variables' but, some solidity code's Libraries have struct type. As far as I know that(may be wrong) struct type is 'storage' and 'state ...
2
votes
1answer
20 views

how does ERC1820 work

1820 keeps the record with mapping(address => mapping(bytes32 => address)) internal interfaces Which address is the actual contract which one is the interface? I assumed the first address is ...
0
votes
1answer
9 views

Why 'throw' is a problem in this Solidity code?

I found this code at the following site: Ethereum Griefing Wallets for (uint i=0; i<investors.length; i++) { if (investors[i].invested == min_investment) { // Refund, and check for failure. ...
0
votes
2answers
23 views

Finding a better way to retrieve information about struct

I've run into a problem about getting information about the structs. The code is written below: pragma solidity ^0.4.23; contract Transport { address public manager; Batch[] public ...
0
votes
0answers
14 views

How to instatinate and test Registry/Logic contracts with Geth?

I am having troubles getting below contracts tested with geth Storage Contract pragma solidity ^0.5.2 < 0.7.0; contract Storage { uint public val; } Registry Contract pragma solidity ^0.5....
0
votes
0answers
23 views

Why am I getting the error "Expected pragma, import directive or contract/interface/library definition?

I have "pragma solidity ^0.5.9" at the start of the file yet I still get this error. Listing.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition. ...
2
votes
1answer
23 views

Documenting Smart Contracts and Dapps - community standards and tools

Do you guys know of any kind of documentation standards that are widely used within the Ethereum community? Any kind of documentation tools will also be of great help. Thanks in advance.
2
votes
2answers
104 views

Is my ethereum solidity contract correct and safe

I am very new using Solidity to create Ethereum contracts and would like to know if the contract I have created is first correct and safe to use. What I am doing in this contract is allowing the user ...
0
votes
1answer
18 views

In node.js event is not fired

I am using web socket to get event. sending transaction works fine. but event is not fired. also I referred Web3 events not working but it does not work, too. I used eventemitter also. but it did ...
0
votes
1answer
43 views

what does external means ? how can i call the test2() inside my class

pragma solidity ^0.5.7; contract Test { function test() public view returns (uint){ return 10*10; } function test2() external view returns (uint){ ...
1
vote
1answer
21 views

How to test events that were sent by inner transaction / delegate call?

Usually, using truffle I can check for events like this: let { logs } = await myContract.doSomethingImportant( xxx ); // 1500 tokens are expected to get expectEvent.inLogs(logs, '...
2
votes
1answer
23 views

Finding an element in array

pragma solidity ^0.4.17; contract Transport { address public manager; Car[] public carArray; Bike[] public bikeArray; struct Car { uint carId; address carOwner; } ...
1
vote
1answer
38 views

Solidity Error Address / Address Payable

I'm currently learning solidity programming to create a basic smart contract based on a 2018 tutorial where solidity was using version 4. I'm currently using truffle v5.0.21. I understand that there ...
1
vote
1answer
21 views

Newbie. Getting cannot read property 'abi' of undefined when trying to deploy on Ubuntu

let abi = compiled.contracts.example.PartyTime.abi; This is the line of code that is causing the error. I copied the abi code from Remix into an abi.json file. But it doesn't seem to be reading it ...
2
votes
0answers
31 views

How the following pairing equality be verified in Etherum Smart contracts?

I have found available precompiled contracts in solidity. For example, this answer enter link description here points out a precompiled contract that can verify BLS signature. However, looking to the ...
1
vote
1answer
11 views

Was testing this code I found online but keep getting errors?

pragma solidity ^0.5.0; contract Courses { struct Instructor { uint age; string fName; string lName; } mapping (address => Instructor) instructors; address[] public instructorAccts; ...
2
votes
2answers
17 views

What is the latest implementation of approveAndCall() - Solidity ˆ0.5.0

Just curious for some background on approveAndCall() 1) Is it initially an ERC223 method ? or is it officially part of the ERC20 interface ? 2) Also Im working with an old contract so Im wondering ...
1
vote
1answer
18 views

I've given Gwei less than 0.1 for a transaction, and it's been an hour, and it is not showing up in etherscan!

I know I pretty much messed up with Gwei, I've given it < 0.1. My doubt is if the transaction gets failed will the funds get back to my wallet or lost forever and how much time will it take for the ...