Questions tagged [smartcontracts]

Smart contracts also known as a smart property are computer protocols that facilitate, verify, or enforce the negotiation or performance of a contract, or that make a contractual clause unnecessary.

3050 questions
202
votes
3 answers

What is an appropriate type for smart contracts?

I'm wondering what is the best way to express smart contracts in typed languages such as Haskell or Idris (so you could, for example, compile it to run on the Ethereum network). My main concern is: what is the type that captures everything that a…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
143
votes
4 answers

In Ethereum Solidity, what is the purpose of the "memory" keyword?

When looking at sample contracts, sometimes arrays are declared in methods with "memory" and sometimes they aren't. What's the difference?
fivedogit
  • 8,374
  • 7
  • 34
  • 43
37
votes
8 answers

How to find out if an Ethereum address is a contract?

An address in Solidity can be an account or a contract (or other things, such as a transaction). When I have a variable x, holding an address, how can I test if it is a contract or not? (Yes, I've read the chapter on types in the doc)
bortzmeyer
  • 34,164
  • 12
  • 67
  • 91
26
votes
11 answers

How to generate a random number in solidity?

I have a couple of keccaks, which could be reduced to one if I would find a cheap way to get parts of the created uint. pragma solidity ^0.4.19; contract test { function test() { } function sup() returns (uint test) { uint _test =…
Garry Plays
  • 377
  • 1
  • 3
  • 5
25
votes
4 answers

How to return mapping list in Solidity? (Ethereum contract)

I want to make a simple smart contract that has a list, can set item, and can get the list. Code in solidity: contract lister { mapping(int => string) list; int id = 0; function getList() returns ( /*HERE*/ ) { return list; …
6londe
  • 557
  • 1
  • 8
  • 17
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
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
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
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
17
votes
6 answers

error[E0463]: can't find crate for `core` / note: the `wasm32-unknown-unknown` target may not be installed [NEAR Protocol]

I see this error in the Terminal while building a Rust application (which happens to be about NEAR Protocol, if you're curious): error[E0463]: can't find crate for core note: the "wasm32-unknown-unknown" target may not be installed How can I fix…
Dorian Crutcher
  • 381
  • 2
  • 7
17
votes
4 answers

UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit

I am trying to deploy my simple solidity smart contract onto the Rinkeby Network but I keep getting the error: UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit. My solidity code is…
Jason
  • 1,059
  • 1
  • 13
  • 32
16
votes
5 answers

How to send an ERC20 token with web3js

I'm currently using the 0.2x.x version of the Web3 JavaScript API. I deployed my custom ERC20 token by creating smart contract in solidity (on REMIX IDE). I installed the MetaMask and had a test on https://wallet.ethereum.org/ to send some custom…
rachel_hong
  • 471
  • 2
  • 6
  • 15
15
votes
2 answers

how to swap tokens on uniswap using web3 js

I am trying to use uniswap contract method to simply swap eth for token, using eth from metamask wallet. Uniswap contract method is: function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external …
user3338991
  • 431
  • 2
  • 5
  • 9
15
votes
3 answers

Ethereum Solidity - Does require() use any gas?

Google has failed to give me an concrete answer, does using the require() function in Solidity use up any gas? Even if the statement in the function is evaluated as true?
mrsulaj
  • 398
  • 3
  • 12
14
votes
2 answers

Solana Test Program Anchor Test failing tsconfig.json" > needs an import assertion of type "json"

I ran anchor test --skip-deploy and all it should do is initialize my program, but all I get is this error, that I cannot resolve. I checked the tsconfig.json settings they should be fine. This is just the default anchor setup and I'm not importing…
Julia
  • 981
  • 1
  • 8
  • 16
1
2 3
99 100