Questions tagged [solidity]

Solidity is a language for smart contracts for blockchain technologies like Ethereum. It is designed to compile code for the Ethereum Virtual Machine. Use this tag for questions about programming smart contracts using the Solidity language.

Solidity is an object-oriented language whose syntax is similar to that of ECMAScript, but with static typing, and it is designed to compile to code for the Ethereum Virtual Machine for use in smart contracts in blockchain technologies.

6642 questions
24
votes
2 answers

Why does Solidity suggest me to implement a receive ether function when I have a fallback function?

The recent change in Solidity changed the fallback function format from just function() to fallback(), which is pretty nice for beginners to understand what is going on, but I have a question about a suggestion that the compiler gives me when I…
Baiqing
  • 1,223
  • 2
  • 9
  • 21
24
votes
2 answers

Module is extraneous npm

I've checked that the connect-privkey-to-provider module is in the dependencies. However, it keeps saying Module 'connect-privkey-to-provider' is extraneous npm and cannot find module 'connect-privkey-to-provider'. What's wrong with my code? PS…
1Sun
  • 2,305
  • 5
  • 14
  • 21
24
votes
15 answers

npm solc: AssertionError [ERR_ASSERTION]: Invalid callback specified

I am trying to compile solidity smart contract using npm solc. I tried to follow different examples. Link to example: https://medium.com/coinmonks/how-to-compile-a-solidity-smart-contract-using-node-js-51ea7c6bf440 I wrote my code like…
Mouazzam
  • 469
  • 1
  • 4
  • 15
24
votes
1 answer

Converting Object Promise to String in Javascript

I'm working with React, Next.Js, semantic-ui-react and Solidity. It is my goal to print out the users address (from MetaMask) and a ProjectTitle (set by User) as meta infomation for a semantic-ui-react card. To print out the address in the 'header'…
Saensation
  • 581
  • 1
  • 4
  • 7
23
votes
1 answer

How would I send an eth value to specific smart contract function that is payable in ethers.js?

I'm trying to call a payable function on a smart contract that only accepts one argument. How would I send an eth value to this function in ethers.js along with the function call? The docs don't seem to give much examples on the best way to do…
23
votes
11 answers

solidity transaction error, The called function should be payable if you send value and the value you send should be less than your current balance

I'm learning solidity on remix. I was following some tutorial video on youtube and I've got stuck trying to build 2 contracts. contract ERC20Token has function which increases balances. And Mycontract instantiates and call the mint function. I did…
Baaam Park
  • 415
  • 1
  • 5
  • 7
23
votes
2 answers

Copying of type struct memory[] memory to storage not yet supported

How do I add a new empty Parent instance to the list of parents in the code sample below? I keep getting UnimplementedFeatureError: Copying of type struct Test.Child memory[] memory to storage not yet supported. Minimal example: contract Test { …
Jonas H.
  • 2,331
  • 4
  • 17
  • 23
22
votes
9 answers

String array in solidity

I came across quite a common problem that it seems I can't solve elegantly and efficiently in solidity. I've to pass an arbitrary long array of arbitrary long strings to a solidity contract. In my mind it should be something like function…
Fabio
  • 415
  • 1
  • 5
  • 14
22
votes
14 answers

String concatenation in solidity?

How do I concatenate strings in solidity? var str = 'asdf' var b = str + 'sdf' seems not to work. I looked up the documentation and there is not much mentioned about string concatenation. But it is stated that it works with the dot ('.')? "[...] a…
tObi
  • 1,864
  • 3
  • 20
  • 32
21
votes
6 answers

How to Logout of MetaMask account Using web3.js

I am using MetaMask for sending transactions to contract in my DApp. I need help in How to Disconnect MetaMask account from my DApp when the user clicks on logout button. Front-end: ReactJS Back-end: Web3js, Solidity (Ethereum)
Umair Janjua
  • 324
  • 1
  • 2
  • 11
20
votes
2 answers

what approve and allowance methods are really doing in ERC20 Standard?

The problem is what allowance and approve are really doing? And what is _spender and what is it doing? Is there anybody who can explain it to me? contract Token { uint256 public totalSupply; function balanceOf(address _owner) constant…
shahabvshahabi
  • 937
  • 2
  • 7
  • 18
19
votes
2 answers

How to set default parameters to functions in Solidity

I came across below example from the Solidity Documentation and have similar code in my project and want to set default value to key parameter if the key is not passed from the caller pragma solidity ^0.4.0; contract C { function f(uint key,…
MBB
  • 1,635
  • 3
  • 9
  • 19
18
votes
1 answer

How can I use different addresses to call functions in Hardhat tests and scripts?

When running tests and scripts, all functions are called by the first address provided by Hardhat. I'd like to know if there's a way to change the calling address within the same test or script. Thanks in advance!
Nico
  • 181
  • 1
  • 4
18
votes
1 answer

Warning: Function state mutability can be restricted to pure function

I am new to solidity and I have been trying to print out simple messages using functions in solidity, but I have failed to deploy successfully, and there is an error that I can not figure out what's wrong. This is what I have tried so far: pragma…
Alo_159
  • 181
  • 1
  • 1
  • 3
18
votes
1 answer

Handling user profiles in Ethereum DApps

I'm in the process of creating an Ethereum DApp. The DApp consists of users who have associated data like email, name, and a profile picture. I would like to store the contents of the user within IPFS as a JSON object and reference this on chain…
Dondrey Taylor
  • 290
  • 3
  • 10