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

troubles with import in Remix IDE

I have the following error when try to compile: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol:5:1: ParserError: Source "https://github.com/...
0
votes
0answers
20 views

Unhandled Rejection (TypeError): Cannot read property 'call' of undefined

I am working on a ethereum dapp and am struck with the following errors, concerned code pieces have been attached. App.js async loadBlockchainData() { const web3 = window.web3 const ...
0
votes
1answer
21 views

How can a Smart Contract ask informations to a node?

I need to code something quite complex compared to my experience. Just for academic purpose, I'm supposed to have a lightweight blockchain that connects a group of nodes; in this blockchain every node ...
0
votes
0answers
31 views

Withdraw erc20 DAI token from smart contract but get DAI/insufficient-allowance

I try to withdraw DAI token from smart contract into my wallet on kovan net that holds around 20 dai by executing the following: const mantissa = (numberOfDaiTransfer * Math.pow(10, underlyingDecimals)...
1
vote
1answer
39 views

How to generate solidity encode function signature from Javascript?

What I am trying to achieve is like , i should be able to call a set of solidity functions dynamically based on some criteria. i'm using call() method to achieve the same. (bool success, bytes memory ...
0
votes
0answers
19 views

How many key-value entries can be stored in Solidity Mapping data structure?

mapping(uint => uint) public myMap; function store(uint key, uint val) public { myMap[key]=val; } function retrieve(uint key) public view returns (uint){ return myMap[key]; } Considering ...
1
vote
0answers
22 views

scope of references to external smart contract, global variables, eleminiate redundant code

Imagine that there's a smart contract deployed which contains a number of sub-contracts like so: pragma solidity ^0.5.0; contract A { address contract = 0x6663130dDfF21E3BC963Ee902005223b9A202106; ...
0
votes
0answers
19 views

Web3 Console Test -> tokenInstance.balanceOf(boom).then(function(bal) {balance = bal;}) ERROR

Learning Web3 right now and I am getting an error when I try to read the token balance of a Ganache account when I run the following line in the console: tokenInstance.balanceOf(boom).then(function(...
0
votes
1answer
14 views

Smart Contract management

I'm new to blockchain development. I watched a lot of udemy courses about Solidity. I think I understand how smart contracts work but I have 2 questions. Would it be possible to manage an application ...
1
vote
0answers
32 views

bitwise multiplication to reduce gas cost

This is the multiplication method from the SafeMath library. /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*...
0
votes
0answers
52 views

How to get all the information of a uniswap trade using web3?

I would like (if possible) to read the exact trade made in a transaction where and address interact with Uniswap (or other DEX) using web3. Using Etherscan is quite simple to read the tokens swapped ...
2
votes
0answers
23 views

Are ERC-1155 tokens always atomic?

I am creating an ERC-1155 smart contract whereby I create a number of different tokens and also want to be able to create new tokens on the fly. The code is something like: import "@openzeppelin/...
0
votes
1answer
13 views

Increase values in array

I am increasing the value at a particular index in Solidity but it is giving me bad instruction error. Can anyone tell me what I am missing here? Please check the sample contract for reference: pragma ...
0
votes
2answers
148 views

Invalid Big number

When i try to deploy my example contract it gives me the error creation of Auction errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", ...
0
votes
2answers
18 views

ParseError: Expected ';' but got '(' emit sent(_from, _to, _value);^

I'm currently doing a smart contracts short course and we got the code below but I've swapped out the event for emit. Now I am getting the following error: ParseError: Expected ';' but got '(' emit ...
0
votes
1answer
14 views

How to pass quotes inside a string via remix?

How do you pass in a value as a string via remix - if that value includes quotes? For example A function takes a string - in remix I enter: <path id="svg_1" d="m-44.5,88.5c234,144 ...
0
votes
1answer
20 views

Contract Polymorphism based on address type cast issue

I am new to solidity and having difficulty understanding polymorphism and address typecasting of contracts. I am passing the address of child_1 contract to getChild2Value(address adr) which type cast ...
0
votes
1answer
11 views

How to handle calling instance method in a constructor?

Is it possible to call (or schedule a call) to class method in constructor? contract Foo constructor() { owner = msg.sender; this.setUp() } setUp() { // run some setup code ...
0
votes
0answers
26 views

invalid opcode error

I would like to set array contents using data present in another one. I'm tring to use the function below but got opcode error. Can anyone explain me why? function getfreecars() public returns(uint) { ...
0
votes
0answers
23 views

Verify & Publish Source Code

I tried to Verify & Publish Contract Source Code for my token and the error happened like this Compiler debug log: Error! Unable to generate Contract ByteCode and ABI (Compiler Exception) For ...
0
votes
1answer
33 views

How to initialize a mapping of structs with a mappings?

I have a mapping of a struct, which has a mapping to another struct: uint256 public questionIdCounter; mapping(uint256 => Question) public questions; struct Question { uint256 ...
0
votes
1answer
41 views

Solidity: Wrapping an ERC20 token inside of a new token

Is it possible to wrap and track a ERC20 token amount in another token? Would I need to use ERC-721 to do this? Let's say I send my ERC20 token to a specific smart contract which will wrap it in a new ...
1
vote
1answer
226 views

INSUFFICIENT_OUTPUT_AMOUNT error when attempting Uniswap swap from a contract

While I'm able to successfully swap ETH for DAI, I'm running into an INSUFFICIENT_OUTPUT_AMOUNT error when trying to swap DAI for ETH using swapExactTokensForETH, even with amountOutMin set to 0. I ...
0
votes
1answer
20 views

Push large number of items in mapping with constructor or other methods

I would like to push large number of items into mapping. Prototype looks like this mapping (uint => string) ipfs_hashes; constructor() ERC721("GameItem", "ITM") public { ...
1
vote
0answers
27 views

why does it copy into memory?

Let's say I have the following.. contract D { function again(uint256[3] memory bla) external returns(uint) { return bla[0]; } } contract A { function test(D f, ...
1
vote
0answers
10 views

why would I need to use `memory` in front-of parameter?

Let's say I have the following contract. contract D { function again(uint256[] memory bla) public returns(uint) { return bla[0]; } } contract A { function test(...
0
votes
1answer
51 views

Metamask shows “ALERT: Transaction Error. Exception thrown in contract code” but transaction succeeds without error

I'm working on a dapp . and metamask show me error Metamask shows “ALERT: Transaction Error. Exception thrown in contract code” . I have successfully deployed the contract and the error come when i ...
0
votes
0answers
15 views

make contract able to receive funds

i added this code to my contract function withdraw() public onlyOwner{ msg.sender.transfer(address(this).balance); } receive() external payable {msg.value} ...
1
vote
2answers
44 views

Implementing ERC-1155 contract on the fly

I want to implement an ERC-1155 token to represent ownership of videos. Creating such a contract is relatively easy: import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; contract ...
1
vote
0answers
20 views

How to implement variable interest rates efficiently

If a smart contract wants to pay interest on a balance of a user that's pretty much straight forward. You record the balance and the timestamp when a token was deposited and when the token is ...
1
vote
0answers
11 views

IPFS not returning anything

const ipfsClient = require('ipfs-http-client') const ipfs = ipfsClient({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' }) uploadAsset = (cost) => { console.log("Submitting file ...
0
votes
1answer
19 views

Is it possible to set up a mechanism in a smart contract that periodically iterates over a list without being triggered by a transaction? [duplicate]

I want my smart contract to offer a refund service. It must periodically check the start date of a reservation stored in a list of strucutures and if it coincides with the current date, a control ...
0
votes
1answer
18 views

array problem invalid opcode

new to ethereum. I'm tring to write smartcontracto to manage car rental. Can anyone explain me why the function to insert new car is not working (code below): function insertnewcar(string memory model,...
0
votes
1answer
20 views

one transaction with several actions

I am wondering if the following code will produce the transaction with two actions: pragma solidity ^0.7.1 import "https://github.com/bla-bla-bla/contractA.sol"; import "https://github....
0
votes
1answer
18 views

Function does not execute sequentially [closed]

I'm trying to check in a JavaScript function if checkVehicleExists returns a true or false before proceeding with my if else statement which will depend on whether checkVehicleExists is true or false. ...
0
votes
1answer
24 views

Function calls in React to deployed contracts return nothing

I have a simple lottery contract. When I call functions to it from Remix IDE I get the expected result. However, when I make calls to it from React, I get nothing back (such as from manager() or ...
0
votes
1answer
17 views

Trying to check if mapping exists, TypeError: Type uint256 is not implicitly convertible to expected type bool

I am checking if a struct exists in vehicleList and returning true if it exists and false if it does not. However, the function produces an error and I can't understand why it does not work. TypeError:...
1
vote
2answers
29 views

Are smart contracts' functions names visible?

If I deploy a smart contract (for private use) on the Ethereum blockchain, can other people see the names of the functions it contains? Assuming the abi.json file is not published. If not, how does ...
0
votes
0answers
20 views

estimating gas costs for dapps

I am new to ethereum and I am trying to build something like a vault where you can withdraw and deposit assets, based on the dApps protocols you are using (e.g :- yEarn, aave). I know there will be ...
0
votes
0answers
12 views

Weird behaviour with prettier in VS Code

So Prettier is behaving quite weirdly for me. Lets take this simplified interface: interface Token { function getTotalSupply(address _market, TokenType _tokenType) external view returns (uint256); ...
0
votes
0answers
43 views

Transaction has been reverted by the EVM - How to deduce the revert reason in this case?

I get this error when I call a function that changes the state of the smart contract from the frontend: Error: Transaction has been reverted by the EVM: { "blockHash": "...
0
votes
1answer
43 views

How to acquire ERC20 tokens on a test net?

I want to interact with a smart contract on Rinkeby, but I need to have ERC20 tokens to do so. I know how to get Ether on Rinkeby, but how would I get ERC20 tokens? Do I have to deploy and ERC20 ...
0
votes
0answers
21 views

Empty msg.sender in contract function when called from Remix testing

I have a very simple contract function (bogusFunc) that makes use of the implicit msg.sender: function bogusFunc(uint256 _val) public { // use _val for something user_list.push(msg.sender); } ...
0
votes
0answers
18 views

How to get rid of “Gas estimation errored with the following message” in this case?

In my front-end, I try to call a function called endAuction. In endAuction, I transfer payment to a seller and participants. While calling it from the front-end the transaction fails without any ...
0
votes
1answer
29 views

how does gas get taken from the account?

Let's say we call the function: function nice(uint a) public returns(uint256){ k = 100; z = 100; f = 100; require(a == 5); ...
0
votes
1answer
23 views

How to call a function in parent contract from children contract?

I am new to solidity.. please bear with my foolish question I would like to get the variable called num in a parent contract from its children. So, what I have in my mind is to try to get the address ...
0
votes
0answers
17 views

why can I specify `memory` if function is internal?

In the latest compiler versions, we can do the following: function balanceOf(uint[5] memory data) external view returns (uint256) { Until some version of the compiler, i couldn't specify memory, ...
0
votes
0answers
20 views

how does calldata not work in this case?

pragma solidity ^0.7.4; contract D { function test2(uint[1] calldata good) external { uint c = good[0]; } } This code is perfectly valid. What I do is deploy ...
0
votes
0answers
10 views

how to access the element of struct in array and mapping using assembly?

how to access the element of struct in array and mapping using assembly? my code case: contract Test { struct User { address addr; uint256 tokenAmount; } mapping (uint256 =...
0
votes
0answers
11 views

How to Submit 0.4.10 Sol version Contracts to Etherscan for Verification

I am trying to verify a Solidity Contract I wrote using Remix written in Solidity version 0.4.10.The problem is that Etherscan wont allow me to select Solidity Version 0.4.10 for my Project.