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

Read and write products using solidity

I am new to Solidity, trying to store a product in the purchaser wallet and retrieve the information from the owner wallet. I have some ideas but didn't know which one will be best. To store an ...
1
vote
1answer
14 views

What is words in uint256?

Let's take two variable: uint256 public smalldata = 50000; uint256 public data = 500 * (10**6) * 10**18; The first on prints: BN { negative: 0, words: [ 50000, <1 empty item> ], ...
0
votes
0answers
18 views

Problem with running truffle code with node.js

I am trying to run truffle code with Node.JS in the backend to deploy contracts. I want to be able to do this interactively and I am intending to use the Express Library to interact with the Node ...
0
votes
1answer
17 views

How to convert to 8 digits in etherum

I have a token that has 8 digits, so the output is 4762575931 instead of 47.62575.. How can i change this so this works on UI and for metamask input? I know there is the function to wei but this is ...
1
vote
1answer
15 views

Mocha assertions not returning correctly on assert.equal with BN

Is this an issue with deep matching/object identity? AssertionError: expected <BN: 204fce5e3e25026110000000> to equal <BN: 204fce5e3e25026110000000> It seems strange that chai.should ...
0
votes
1answer
28 views

How can I turn this into a human readable output? [closed]

I have this buy function but the output gives me a transaction Nr. or whatever this is async function buy() { var a = document.getElementById("amount").value; var accounts= await web3.eth....
0
votes
0answers
18 views

Oraclize ( provable) updates the value only one time

I'm trying to write a smart contract that gives me the current timestamp. The very important part is that i want this to happen locally, not on test networks. After some research, i installed ethereum-...
0
votes
1answer
19 views

Solidity error message on compilation (DeclarationError: Identifier not found or not unique. using Address for address;)

I'm trying to compile a code for a crowdsale contract (Timed and with allowance) from openzeppelin library that is based on a deployed token. However during compilation on remix i get a syntax error ...
0
votes
1answer
8 views

how to send parameters to smart contract while deploying using metamask

I am trying to deploy a smart contract using BrowserSolc and Metamask. and deployed successfully when the contract doesn't have constructor parameters but now I am trying to deploy with the ...
0
votes
0answers
11 views

Contract is not deploying properly on Geth private network using web3j SDK

I am new to Ethereum. I have created private blockchain using Geth on my local and trying to deploy my smart contract using java web3j SDK. I am able to deploy my contract using java and getting ...
0
votes
2answers
21 views

Solidity 0.6.1 Receive Fallback Forwarder reverts due to insufficient gas

I am playing around with Solidity 0.6.1 and trying to build a simple funds forwarder. So ETH is sent to the contract and it sends the funds to another address. I deployed it to Ropsten. But every ...
0
votes
1answer
27 views

msg.sender not increasing the balance

I am trying to execute the following code obtained from`Solidity Tutorial pragma solidity 0.5.4; contract ERC20Token { string name; mapping(address => uint256) public balances; ...
0
votes
1answer
33 views

Using the correct/best solc version with Truffle and general tooling setup

I haven't worked with Truffle/Solidity for a while and I am trying to get my environment/toolchain configure correctly. I have some questions regarding the compiler config. I was originally not ...
0
votes
0answers
25 views

gas estimation fails when trying to run a recursive function? Is there an alternative?

I have been trying to traverse a graph kind of data structure and the only way to do this is by using a recursive function is what I feel. So, now when I try to execute my contract code in remix it ...
1
vote
1answer
24 views

Logic help needed, how to transfer funds to the address who placed bets on winning team?

This is a betting application and right now -> if I place bets on HOME, the amount gets stored but I want to transfer the amount only to the address who placed bets on winning team. I have developed ...
0
votes
1answer
19 views

Multiple callbacks with provable random oracle

I'm making a simple lottery game where there are hourly, daily and weekly prizes. My contract has functions to pick winners for each of these game types. Each game types will have different number of ...
0
votes
0answers
20 views

Is there a graph data structure in solidity?

I am trying to achieve a file lineage information Dapp and I need a graph kind of data structure for that. I know I can always write one but is there a ready to use data structure that is efficient ...
0
votes
1answer
21 views

Always raising “Gas required exceeds allowance or always failing transaction” when the condition of require() is not met

I tried to run the following code to check the error message when the condition of require() is not met. pragma solidity ^0.5.16; ... function addUser(string memory name) public returns (int) { ...
1
vote
2answers
24 views

Can i disable direct transactions to smart contract address?

I want to use rewardsAmount variable to calculate my rewards: uint rewardsAmount = 0; // Only here i can withdraw rewards function withdrawRewards() onlyOwner external { require(rewardsAmount !=...
0
votes
2answers
17 views

How to diagnose a “Error: Transaction has been reverted by the EVM”?

This the error intercepted from my javascript, using web3.js Error: Transaction has been reverted by the EVM: { "blockHash": "...
2
votes
1answer
18 views

How to check if a mapping has not been written yet?

I have this mapping: mapping (uint256 => string ) private storedData; I am trying to do this: modifier dataNotStored(uint256 _index) { require( keccak256(abi.encodePacked(storedData[...
0
votes
1answer
20 views

How to resolve this error in solidity “The constructor should be payable if you send value.”?

In this solidity code the finalizeRequest() is giving a run-time error. Here is the error : Campaign.finalizeRequest(uint256) 0x692...77b3a transact to Campaign.finalizeRequest errored: VM error: ...
0
votes
1answer
22 views

Calculate most frequent value in a array in solidity

I have an array something like [0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2]. I want to find the most frequent value. If two are more are having highest frequency, the first occurance should be the result. ...
0
votes
0answers
24 views

Not able to call the solidity function through App.js? Anyone know how to call a solidity function?

I'm trying to call a Solidity function from App.js, but I'm unsuccessful even after a number of tries. Its a very simple function betOnTeam(). Inside this function I just want to check condition and ...
0
votes
0answers
17 views

Error => invalid address, on passing arguments to function

so I created a function but then I needed to make it dynamic so that I will be able to call the same function body just bypassing the arguments on click of a button I am fetching the values from HTML ...
0
votes
2answers
26 views

Trying to reference function from parent contract - Member “xxx” not found or not visible after argument-dependent lookup in address

I am trying to make a parent contract which deploys a child-contract for each unique caller (which does not inherit from parent contract, but calls one of the parent's functions). I have looked up ...
0
votes
2answers
32 views

Invalid opcode exception when trying to resize a storage array

I wrote this function: function removeClaim(uint256 _claimId) public returns (bool success) { require(msg.sender == owner || msg.sender == claims[_claimId].issuer); // Emit event and store ...
0
votes
1answer
23 views

Which Pattern to follow to create contract?

I have an ad campaign and I want to store data(like campId, number of impressions, start date, end date etc.) of each campaign on blockchain. Also, whenever I will pass campId, I should be able to ...
0
votes
1answer
28 views

how to transfer a specific balance from a smart contract?

Whenever someone buys a smart-contract the amount (in Wei) get stored in SC(Smart Contract) address(this) += msg.value. Now I am trying to create a function to redeem the balance of the SC ...
0
votes
0answers
33 views

Error: gas required exceeds allowance (8000000) or always failing transaction [duplicate]

I deployed a test ERC20 to a private ethereum blockchain. It deployed fine because I can get the transaction receipt, see the logs and everything looks ok as far as I can tell. However, when I try to ...
0
votes
1answer
20 views

Listen to a solidity event from a smart contract function [duplicate]

I have the following event: event WaitingPlayer2(address indexed player2); Which I call through: function partecipateAsPlayer2(address player2) public{ emit WaitingPlayer2(player2); } Is ...
0
votes
0answers
15 views

zeppelin tutorial smart contract (noob alert) can't connect to network

I am following this tutorial - https://docs.openzeppelin.com/learn/deploying-and-interacting#local-blockchain Everything was going good until i was asked to type the command - $npx oz accounts - ...
0
votes
1answer
34 views

Function stopped working? No check is being done now on transfer function

I created a function to deposit and transfer ether and it was working great until i tried to deploy again and now the transfer function is not working anymore No errors are being thrown, the transfer ...
0
votes
1answer
24 views

getBalance of shows the wrong balance

I have this code to show the erc20 token balance of an account var tokenAddress = '0xb97E9bBB6fd49865709d3F1576e8506ad640a13B'; var walletAddress = '0x62f28320f688A7A4e0021c55d7ffD1acd770A133'; ...
0
votes
2answers
32 views

Cannot transfer ether from smart contract to another address

I am using truffle and when we type truffle develop it provides us with 10 address ** So, the problem I am facing is I have created 2 functions one to deposit ether and the other one to transfer the ...
0
votes
0answers
15 views

How is this possible using web3 and truffle accounts [closed]

all i want is this Alice sends contract 1 Ether. Now contract has 1 Ether. Contract forwards 1 Ether to Bob. Now contract has 0 Ether. I know this is possible but to accomplish it with front end AND ...
0
votes
1answer
27 views

cant call contract instances on my UI

I want to be able to display the read functions of my contract on a UI. These are the calls I make to my UI Those functions work perfectly in the console using node but when i try to call them from ...
0
votes
1answer
20 views

How to store a erc token instead of eth into solidity function [closed]

How to store a token instead of eth into solidity function below are the code for storing ether. how to change into erc 20 token instead function deposit() public payable{ require(msg.value >= 1 ...
0
votes
0answers
37 views

Whas this Error Code and how can i get rid of it?

Im using this code to query the balance of the logged-in address // get sellPrice function sellPrice() { web3.eth.getAccounts(function (error, accounts) { contract.sellPrice(address, ...
0
votes
2answers
35 views

Making contract compatible with newer solidity version

I have a simple ERC20 contract however it doesn't work with modern solidity compilers, Could anyone make my contract compatible with solidity newer than 0.5.16? Thanks. Here is the code, it only ...
0
votes
0answers
18 views

How can I make function calls in UI based on these functions of my smart Contract [closed]

I want to call these functions as soon as an address is logged in to my UI Whats the best way to achieve this with metamask, web3 js?
0
votes
1answer
29 views

How can I access elements in Object?

I have my contract object and this has attributes like contract.balanceOf contract.myDividends contract.totalSupply contract.myTokens I get an error this._eth.call is not a function when i try to ...
0
votes
1answer
23 views

How to properly initialize nested storage array/struct?

contract Contract { struct A { int a; } struct B { A[] as; } mapping(address => B[]) bs; function addB(B memory b) { bs[msg.sender].push(...???...); } } I have nested hell of arrays and ...
0
votes
0answers
18 views

How can we send ether to smart contract address and then transfer it to a account? [closed]

Any ideas, code or suggestions is welcome I am using truffle ,web3 ,metamask Can we send rawtransaction to contract address and then Retrieved the amount? I need to deduct amount from 2 people ...
0
votes
0answers
19 views

Accessing a storage array is causing my contract to revert with no explanation

I have the following contract: // Inspired by https://fravoll.github.io/solidity-patterns/eternal_storage.html pragma solidity ^0.5.8; import "./lib/Ownable.sol"; import "./MemberStruct.sol"; ...
0
votes
2answers
33 views

How to access contract attributes?

I have initialized my contract and need to balanceOf the current logged in address const contract = new web3.eth.contract(abi).at(address); contract.balanceOf(function (error, balance) { $(...
0
votes
0answers
15 views

solidity smart contract thats uses off-chain ML model

I'm new. Hopefully this is an appropriate question for this forum. (This is a simplified example). I want to write a smart contract that receives a loan request, and based on certain features of ...
0
votes
0answers
24 views

Transfer ERC20 (usdt) token between two addresses using web3.py

Here is my code: token_from = "0x0d0707963952f2fba59dd06f2b425ace40b492fe" token_to = "0x763015f098cf18cfa28baf25653955f271fb63ff" token_to_private_key = "0x0000000000000000000000000000000" ...
0
votes
1answer
34 views

How to make Information automatically update when account is changed?

To get the account address of the contract that is currently logged in with Metamask I use this web3.eth.getAccounts(function(error, accounts) { document.getElementById('account-address')....
0
votes
0answers
50 views

Cant call solidity function from app.js?

Solidity function Using web3 0.20 version and Cant call solidity BETONTEAM function pragma solidity ^0.4.22; import "installed_contracts/strings.sol"; import "installed_contracts/oraclize-api/...