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
1
vote
1answer
17 views

Why fallback function cannot be declared public in solidity?

When declaring fallback function we needs to make sure that it is declared external but why fallback function cannot be declared as public. Since external is a subset of public why can't we declare ...
0
votes
0answers
18 views

Passing a hash value to function

I'm trying to authenticate users by comparing the hashes created by backend server and contract. Seems like "byte32" values cannot be coerced into strings. So, instead I'm converting it into ...
2
votes
1answer
28 views

“out of gas” message when calling another solidity contract's method

I want to call another solidity contract's method using Call/DelegateCall. Although the transaction seems successful, but I did not get the expected result, and it shows "Although one or more ...
0
votes
0answers
8 views

Etherscan yul optimizer verification

Is it possible to verify contracts on etherscan.io using the yul optimizer? Example truffle-config.js relevant section: compilers: { solc: { version: "0.5.16", settings: { ...
0
votes
2answers
34 views

solidity, how to wait n second function or others solution

I am working on a project for p2p energy trading using blockchain. I am building an experiment on my own to demonstrate the concept for my master thesis. For this project I have two python scripts, ...
0
votes
0answers
8 views

Does Ganache Support Mappings?

I have a function where I am trying to compare the values of 2 mappings. However, I am receiving an invalid opcode error. Which has me confuzzled because I already set the values of both the mappings ...
0
votes
1answer
22 views

How can I calculate percentage of a number in solidity? [duplicate]

How can I calculate percentage of a number in solidity? say I want to calculate 95% of the number 200. How should I go about doing that ?
0
votes
0answers
15 views

Insert data whithout overwriting the already stored whit the same address

i'm new to solidity and i'm developing an easy app. This is the contract i'm working on. It's all functioning but i need to: do some sort of function that return me all the array value whit the same ...
0
votes
1answer
26 views

Error: Returned error: VM Exception while processing transaction: revert when using methods.MyMethods.Send

I am writing a simple betting application that will return double the ether deposited by the player, provided they guess correctly the random number generated by the virtual slot machine. it works ...
0
votes
1answer
25 views

How to withdraw Other ERC20 tokens besides Ethereum from my contract

I'm trying to implement something like this (which works) function withdraw() public { msg.sender.transfer(address(this).balance) } but I need to be able to withdraw ERC20 tokens other than ...
-1
votes
1answer
20 views

i can't figure out why i keep getting this parser error

pragma solidity ^0.5.13; contract WorkingWithVariables { uint256 public myUint function setMyUint(uint_myUint) public { myUint = _myUint; } bool public mybool; ...
0
votes
1answer
29 views

How to call “payable function” via interface in solidity [duplicate]

I have a function marked as payable in contract A and I want to call it from contract B so that msg.value in contract A can have its desired value and contract A must have balance of sent amount , how ...
0
votes
0answers
32 views

How do I get the available reserve size for a given token on Kyber and Uniswap(V2)

I am doing arbitration with some measure of success; but I suspect I am running into edge cases where the available reserve size is less than what I am trying to buy or sell. Something like this: ...
0
votes
0answers
32 views

Error while calling a erc721 contract funciton using go-language

I am trying to call a function which is "mintUniqueTokenTo(address,uint256,string)" in a ERC721 token using go language , but for some reason it is failing. I think one reason could be that ...
0
votes
1answer
46 views

how create address for each ethereum user [duplicate]

I have a group of Ethereum users how do I create an address for each user to send their data on the network?? I want a way to create addresses for each user??
0
votes
1answer
41 views

Deleting an array in storage (>= 0.6.0)

I need to add elements to a resizable myArray and then delete the myArray. I don't know what the length of myArray will be before the loop, and it's not possible to resize a memory array; that leaves ...
1
vote
0answers
19 views

Distributing interest to a set amount of tokens

Consider a contract which manages an unlimited amount of ERC20 tokens. A user can create a token via this contract and give it a name. The contract also acts as exchange for buying and selling tokens ...
1
vote
1answer
33 views

Mapping vs Arrays: duplicating variables gas consumption

I have a contract that has a struct including address and unit, and mapping of a struct, like this. struct User { uint count; address userAddress; } mapping (address => User) users; ...
0
votes
0answers
24 views

Is possible to use a smart contract with custom buyTokens method in TestNet?

I'm trying to test a smartcontract in TestNet that is working in my private ethereum blockchain network. I can deploy it in Ropsten and Rinkeby, but I can not execute my buyTokens method from Remix. ...
0
votes
1answer
48 views

how different users write their data in ethereum network?

How a number of blockchain users save their data in the blockchain network using ethereum. Meaning more than one user sends his data using Python to save it in blockchain networl ?? How do I ...
0
votes
1answer
84 views

Uniswap V2's swapExactETHForTokens: How to know the number of tokens bought

I wrote the solidity function below to swap ether for other tokens on a Uniswap exchange. It works. function buyCryptoOnUniswap1(uint256 etherCost , address cryptoToken) public payable returns (...
0
votes
2answers
47 views

High Gas Cost for Factory Contract!

I've noticed that when a contract factory creates a new contract with the 'new' keyword, the transaction costs an absurd amount of gas as if it were deploying the contract for the first time. I don't ...
0
votes
1answer
14 views

Solidity get() function only returning one string when i ask for all strings in mapping

Can anyone tell why my get() function only returns the string "name" in Remix? I'd like it to return all the values within the users mapping like i've defined, can you help me accomplish ...
0
votes
1answer
19 views

Efficient Alternative to generateCards()

I recently wrote a function that generates 5 cards and saves them to an array: function generateCards() public { for (var i = 0; i < 5; i++) { uint card = uint(keccak256(abi.encode(block....
0
votes
0answers
19 views

Compile error. Fallback function error

I use pragma 0.6.2. I am trying copile in truffle code which contain this lines: fallback() external payable{} I an getting error: The payable fallback function is defined here. fallback() external ...
0
votes
1answer
30 views

Solidity ^0.6.10 returnBalance() returns “VM Exception while processing transaction: invalid opcode”

I am using Ganache and Truffle console. I compile and migrate the following contract: // SPDX-License-Identifier: MIT pragma solidity ^0.6.10; contract EthReceiver { address payable private owner;...
0
votes
0answers
16 views

Is there a way to get revert message by my client?

I have a smart contract with this simple function: function addUser( string memory _username, string memory _nome, string memory _cognome, string memory _email) public isOwner() { require(bytes(...
0
votes
0answers
23 views

Is there a tool to add SafeMath to production code?

There are a lot of tools to prepare JavaScript/CSS code for production, e.g. to minimize, to convert ES8 code to ES5. Is there a tool to automatically apply SafeMath library to a .sol file? The ...
0
votes
1answer
41 views

Weird exchange rate when buying DAI with Ether

I wrote code to buy DAI using ETH on Uniswap V2 as follows: function buyCryptoOnUniswap(uint256 etherCost , address cryptoToken) public payable returns(uint256){ //address cryptoToken = ...
1
vote
1answer
34 views

How to install solc of a specific version?

I want to install solc 0.4.24 but the commands given below installs the new version. sudo add-apt-repository ppa:ethereum/ethereum sudo apt-get update sudo apt-get install solc Or sudo snap install ...
0
votes
1answer
44 views

In Solidity, what's the difference between funtion type and funtion? [closed]

In Solidity, what's the difference between funtion type and funtion? And what can they be used for and how respectively? Thanks!
0
votes
1answer
47 views

Solidity Smart Contract withdrawal ETH with amount from contract address does not work

I have below smart contract and a test program to test transfer ETH out of contract address, but contract’s ETH balance not changed. I tested withdrawAmount(uint256 amount) but the assertion error ...
1
vote
1answer
27 views

method like fallback function for ERC20 tokens?

I want to write a contract that uses USDT (Tether) for payment. How can I use the ERC20 token as an ERC777 token, for example: Use a fallback function that executes when we receive USDT token. Or use ...
0
votes
0answers
156 views

Get the txHash,but on etherscan I get “Sorry, We are unable to locate this TxnHash”?

So Im having some trouble with sending ETH from one account to another trough web3 with an erc20 smart contract and I`m using Infura RPC. So, my process is to send 0.2 ETH from account 1 to account 2 ...
0
votes
0answers
56 views

Encrypted information

First of all, excuse me if this is not the section to ask. I'm trying to find out what information can be encrypted inside the blockchain, i.e. should all the information written in the blocks be (...
0
votes
1answer
32 views

How can a smart contract determine the address sending ETH to it?

I'm learning how to build a smart contract that is able to receive ETH and, if certain conditions are met, send ETH back to the address from which it received it. My understanding currently is that a ...
1
vote
1answer
21 views

using mappings inside structs

I'm trying to use a mapping inside a struct: struct PoolStruct { uint currentUserID; uint activeUserID; uint price; uint minimalReferrals; mapping(uint => address) poolUserList; ...
0
votes
0answers
19 views

Why do solc v0.4.17 and v0.4.18 behave differently with the allow-paths primitive?

Here's an example contract: Nobody.sol pragma solidity ^0.4.17; contract Nobody { function die() public { selfdestruct(msg.sender); } } The solc JSON specification to compile the ...
0
votes
1answer
23 views

Error: while migrating Event: invalid address (arg=“benificiaryAddress”, coderType=“address”, value=undefined) [closed]

let Event = artifacts.require("./Event.sol"); const field= { nameOfEvent : "Music", ticketCount : 100, ticketCharge :10000, durationInMinute :1200 } module....
0
votes
1answer
25 views

Why does Remix's jsVM show incorrect gas?

I tested the gas consumption of a contract in the jsVM, which showed consistent outputs. I then deployed it to mainnet, and the function calls consume much different amounts of gas. Is the jsVM ...
0
votes
2answers
1k views

Swap tokens back to ether on Uniswap V2 Router 02 (Sell tokens)

I am trying to do the reverse action of what I did in this question: Basically sell/swap some arbitrary token and receive ether on Uniswap V2 using IUniswapV2Router02. Here is what I have done: ...
0
votes
1answer
24 views

Passing storage of one library to another library

I have two libraries: A and B as well as contract C using them. Library B, in one of its functions, needs to call a couple of functions defined for A.Storage. The code below compiles, tests are ...
0
votes
1answer
37 views

Token addresses for DAI , USDC and WBTC for IUniswapV2Router02

I have searched a lot but maybe I am looking in the wrong places. Please how can I get the token addresses for USDC , WBTC and DAI that work with Uniswap Router02 on mainnet and kovan. Thanks
1
vote
0answers
16 views

Sharing an event between a contract and a library

I've a contract that uses an event and I want to share it with a library without having a duplicated definition. The event is in the library, and contract uses it from the library. It works but the ...
0
votes
0answers
12 views

Error: CompileError: InternalCompilerError: Stack too deep, try removing local variables

Hello everyone please kindly help me out. I have researched on the error above associated with this block of code. But please is there a way to revise this code so that i can get all the data of a ...
0
votes
1answer
132 views

Swap ether to tokens on Uniswap V2 Router 02 fails

I am trying to buy DAI tokens from my smart contract using IUniswapV2Router02 contract BuyExample{ IUniswapV2Router02 usi = IUniswapV2Router02(...
1
vote
1answer
31 views

Why does retrieving stored data cost so much compared to using calldata in Solidity?

I have a function that I need to pass an arbitrary length array of addresses to. In remix, just calling a function that has an address[] costs around 30k gas for an array of 5 addresses: function fun(...
1
vote
1answer
49 views

In Solidity, Is there any situation, when string is necessary?

In Solidity, Is there any situation, when string is necessary? Please can u explain when I should use string instead of bytes or bytesN? Thanks!
0
votes
0answers
24 views

Polymorphism in Solidity

I understand that Solidity supports contract polymorphism, but what pattern would one use to create abstract data types for use in derived contracts? Motivating example: Say I have an abstract Storage ...
0
votes
2answers
36 views

Can I give multiple address parameters to a payable function?

Newbie here, making my very 1st Smart Contract (a rock/paper/scissors game). I'm using 0.5.11 because that's what the tutorial I'm learning from is taught in. I'd like to call my payable placeBet ...