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
3 views

truffle testing enum

I am trying to test an enum value from a test. This is simplified version of the contract: pragma solidity >=0.5.0 <0.7.0; contract Foo { enum State { StateA, StateB } State ...
0
votes
1answer
7 views

Solidity Compatibility Configuration

I am a cyber security analyst who is new to ethereum and working on a project to study crypto security. It's a series of 22 vulnerable smart contracts that you're supposed to exploit. For anyone who ...
0
votes
0answers
18 views

Setting array.length to 0 triggers an error on solidity 0.5.0

Why setting array.length to 0 triggers an error ? I have a function that deletes an element from a dynamic array of structs within a mapping as follows: mapping(address => MyStruct[]) public ...
0
votes
0answers
13 views

How to read uint256[] array from a method in a smart contract?

I'm using this function in my smart contract. It returns an uint256[] array containing the tokens that the user owns. /** * @dev Returns all of the tokens that the user owns * @return An array ...
0
votes
0answers
16 views

Create an ERC20 Stablecoin

How to create a stable coin with an ERC20 token contract ? Does it require contract to be modified ? Are there some good practices or standards ?
2
votes
3answers
158 views

Handling decimals in somewhat complex math

I'm a bit lost on what to do with the following calculation. The problem is that decimals are being round up/down, which obviously doesn't give me the result I desire. int totalValue = 275000; int ...
1
vote
1answer
14 views

No web3 instance injected following the dApp University Tutorials

I've been following Dapp University's videos on how to make IPFS uploads with Euthereum Smart contracts, and after I manage to 'npm run start' in the command line it opens up the HTML, but it always ...
0
votes
0answers
7 views

stack too deep user function

I am building a dapp, the user structure is composed of multiple attribute so I divided it to 3 structures, but I still have the problem of the deep stack in the registration function struct ...
0
votes
1answer
16 views

Web3 - Cannot read property 'clearSubscriptions' of undefined

While creating a web3 instance, and attempting to call setProvider with a valid provider (Ganache), I get a TypeError. TypeError: Cannot read property 'clearSubscriptions' of undefined Steps to ...
0
votes
2answers
18 views

how does this honeypot works?? 'OpenAddressLottery'

/** * Source Code first verified at https://etherscan.io on Saturday, February 10, 2018 (UTC) */ pragma solidity ^0.4.19; /* * This is a distributed lottery that chooses random addresses as lucky ...
1
vote
1answer
13 views

Auction contract problem regarding highest bid display

I have an Auction contract which has a function like this: function bid() payable{ //calculate and store highest bid value } But because each transaction takes time to mine, so when a user bids ...
0
votes
1answer
16 views

How to pass a document as function argument(upload document)

I am working on a project in solidity where I want to generate a SHA256 hash value for the document. So which means when I choose a file using a function the function should return the hash value. ...
0
votes
1answer
9 views

How much gas does looking up block.timestamp consume?

Trying to get some insight as to whether or not it's more optimal to call block.timestamp repeatedly for comparisons or to set a (memory) variable to hold the value and use it instead. I've looked at ...
0
votes
0answers
7 views

Java class generated with web3j has a “deploy” method wherein initialWeiValue, initialSupply have to be both specified. Isn't it the same amount?

Method in the java class generated by web3j is like this: public static RemoteCall<Crowdfunding> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, ...
0
votes
1answer
11 views

VM error transaction has been revert to initial state [on hold]

pragma solidity ^0.5.8; contract PharmaChain { address public superAdmin; //address of the super admin uint quotlist; enum Status { NotExist, Pending, Aproved, Rejected, ...
1
vote
0answers
14 views

truffle unbox react - front end is unable to read / set state of the contract

I am experiencing problems with the Truffle React boilerplate code that the front end is unable to read / set state of the contract. Here are the details: I unboxed the React boilerplate using ...
0
votes
1answer
15 views

How do I deposit Ether to Smart Contract using Web3.js

So I am creating a web application that interacts with a smart contract that I deployed on the Ropsten TestNet. I am able to withdraw ether from the contract to my Metamask account using a withdraw ...
0
votes
1answer
40 views

Unable to deploy the smart contract using solc compiler in mac

I am trying to deploy the Lottery contract using solc compiler of verison 0.4.17 but it's showing me nothing. But the same contract is working good in the remix ide. I providing you the the Solidiy ...
-2
votes
0answers
8 views

truflle consile error BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null [on hold]

i was getting error in truffle console BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null
1
vote
0answers
7 views

What is the value range of the parameter optimize-runs when running the solidity compiler?

I would like to know what the allowed value range of the parameter optimize-runs is when running the Solidity compiler. I didn't find the answer in the official document of Solidity.
0
votes
0answers
7 views

Transfer function not working properly with calculations

function payWorker1(address schoolId) public payable returns(bool){ require(Schools[schoolId].moneySent == false); require(Schools[schoolId].verified == true); Schools[schoolId]...
2
votes
2answers
25 views

Metamask injects one account in web3, but calls contracts using another account

Building a React app, MetaMask injects web3, I get accounts[0] from getAccounts(), then pass it to my contract functions together with other parameters. I want my modifiers to lock incoming function ...
0
votes
1answer
20 views

signing transactions with web3.js

Im trying to create a node.js based dapp that interacts with ropsten ethereum network via infura node.here we need sign transaction with web3.js. but the code showing error from the contract side. ...
1
vote
1answer
20 views

How to increase the number of test accounts?

I have encountered a problem where I need a large number of test accounts. How can I increase the number of test accounts from 10. Remix and ganache only give 10 accounts. I require more than that.
1
vote
0answers
34 views

openzeppelin,VM Exception while processing transaction: revert

using openzeppelin-solidity to create crowdsale. Then I use this statement to Buy Token: MyCrowdsaleInstance.sendTransaction({ from: purchaser[1], value: web3.utils.toWei("0.5", "ether"), ...
1
vote
1answer
5 views

When I tap buy button in market how does wallet check my allowance instantly?

On CrytpoKitties, when I tap the buy button in a market, MetaMask comes up and shows if I can buy or not based on allowance instantly. How is this possible? Is it making query? Is it included in kitty'...
1
vote
1answer
4 views

Do dapps(contract) check allowance of buyer when he calls buy function?

When a buyer calls a buy function on dapp contract, some dapps check the buyer's allowance before transfer tokens(erc20). Is it usual?
3
votes
1answer
26 views

Ganache + Truffle: how to deploy a contract without considering the gas

I am working with Ganache and Truffle. I am trying to deploy kind of a huge smart contract, but most of the functions in this smart contract are pre-prod functions, so I do not really worry about real-...
0
votes
1answer
41 views

Sending transaction with web3.js

I'm trying to use web3.js with infura.io to interact with my smartcontract. here is my simple greeter contract code pragma solidity ^0.5.7; contract greeter{ string greeting; function greet(...
0
votes
1answer
12 views

pass storage through interface to library

Here is what am i doing: There is a library, accept storage argument as parameter, then do some math and return the result. And there is a contract to call the function in the library, and an extra ...
0
votes
3answers
36 views

Remix: This contract does not implement all functions and thus cannot be created

I'm new here and code with openzeppelin framework 2.2.0. There is no error occurred when compiling with solidity 0.5.8. But when I'm going to deploy the contract, I have no bytecode and cannot ...
0
votes
1answer
16 views

Multiply small rational number to obtain integer piece

I'm trying to make some advanced calculations in Solidity. I was able to successfully implement the algorithm on my contract, but its results are way below zero, and whenever I try to get it with ...
1
vote
0answers
55 views

How to remove whitespace from string?

I have a function where one of arguments is a string. How would I check the string for leading/trailing whitespace and remove those characters? If i get something like this: " " => "" or " ...
0
votes
1answer
23 views

Deploying contract using byteCode

In that example you can see, how to deploy a new contract having just ABI and ByteCode (uses for copy and deploy contracts from mainnet to your testnet for example). /****** Deploying new contract ...
0
votes
1answer
17 views

Hash bytes32 and uint32 in Soldiity 0.5.8

How can we efficiently calculate a hash value for a combination of bytes32 and integer value? Like in JavaScript "someString" + someInt. I tried: function fx(bytes32 _left, uint32 _right) public ...
0
votes
0answers
19 views

What are the prerequisites for smart contract testing? [on hold]

what are the dependencies for testing smart contract? e.g. Test environment, Dev-Test Sync
0
votes
0answers
22 views

where is data store in blockchain? [duplicate]

for example we have contract like this: contract Sample { string public name = "Moore ath John Yuur Gha"; function set(string memory _name) public { name = _name; } ...
0
votes
0answers
7 views

Read contract value from Android

I have deployed successfully a smartcontract onto Rinkeby at the address : 0x69cfa9009Bf2c7a9945a4f8b381db21b26b662d7 It is a tutorial smartcontract that enables an election between 2 candidate. I ...
0
votes
1answer
16 views

Making array in Solidity

From what I have read, an array is made by using square brackets[],(The type of an array of fixed size k and element type T is written as T[k], and an array of dynamic size as T[].)*. When looking at ...
0
votes
0answers
8 views

ecrecover function in solidity [duplicate]

how to extract sub-bytes r,s from bytes(signature). Is there any function to split the bytes into sub-bytes of desirable length starting from some fixed index?
0
votes
0answers
15 views

truffle-assertions: TypeError: Cannot read property 'filter' of undefined

There is a part of my Solidity code: event elo(address pAddress); function test() external { emit elo(m_Registry); } And a chunk of my test: const truffleAssert = require('truffle-...
0
votes
0answers
29 views

How can I comparing fingerprint using solidity language?

I have a fingerprint image stored in IPFS and I want to compare with another fingerprint image, because i need to know if is the same fingerprint ,is there some way, some lib that i can compare this ...
0
votes
0answers
9 views

Error while deploying smart contract ,BadFunctionCallOutput

The log i am having while deploying a smart contract: -------- load log data -------- user.address = 0x2154f8B602c470ae7F10f242DCC88Ae6221bb263 contract.address = ...
0
votes
0answers
39 views

How to decode SHA256 hash value and retrieve data in Solidity

I am working on a project in solidity where i am encode a string to SHA256 hash value, and now i want to decode SHA256 hash value and retrieve the actual data. please help hoe to do it. Below is the ...
1
vote
1answer
24 views

ERC20 token balance is always zero

I'm writing a pre-minted ERC20 token contract derived from openzeppelin-solidity like: pragma solidity >=0.4.24; import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; ...
0
votes
1answer
31 views

Unhandled promise rejection (rejection id: 1): Error: Transaction has been reverted by the EVM:

I don't know where i'm doing mistake. I have deployed my contract through remix and truffle and it was deployed without any mistake but now i'm deploying it from web3 solc@0.4.24 version and EVM is ...
0
votes
1answer
14 views

Getting error in Deposit function in smart contract : The constructor should be payable if you send value

I am getting the error while deposit the amount in remix. Following is my code pragma solidity ^0.4.19; contract Savings { address owner; uint256 deadline; modifier onlyOwner() { require(...
0
votes
2answers
26 views

Accessing private variables using assembly

I would like program an oracle service which I would like to charge a fee for. Therefore, I would store the data of interest as a private variable in my oracle contract. This private variable should ...
0
votes
0answers
34 views

How require() and assert() work in solidity?

I'm trying to validate a condition using require(). If the condition is false for the first time, the contract is stopped and reverted to its initial state. On the other hand, if the condition is true ...
0
votes
1answer
16 views

Is it possible to alter the msg.sender variable when calling another function in the contract?

I have the following contract: pragma solidity >=0.4.24; contract ERC20Interface { string public constant name = "Udacity Token"; string public constant symbol = "UDC"; uint8 public ...