Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
12 views

Reliable way to identify the caller [duplicate]

Is a reliable way to identify the caller with the following code? bool isContract = msg.sender != tx.origin;
0
votes
1answer
17 views

How to confirm transaction as a receiver in metamask?

My question is simple If I want to send some ether to someone in remix like contract Sender { function send(address _receiver) payable { _receiver.send(msg.value); } } Metamask asks me as a ...
1
vote
2answers
41 views

Pass specific address in Web3J send method

How to pass specific address in send method in Web3J? For example, using web3 javascript library, we can pass from address like below. contract.someMethod().send({ from: this.props.accounts[0] }) ...
0
votes
0answers
22 views

sending ether Transaction failed when executing multiple transaction

I am sending ether to an array of addresses. I am getting the nonce value from eth_getTransactionCount. But problem is that the first transaction is successful but for the rest of the transactions are ...
1
vote
0answers
17 views

Return an array of adresses

I have a mapping with the key as an address and the value as an array of addresses. How do I return the array of addresses? In older solidity versions it works. In newer compiler versions I have to ...
1
vote
1answer
23 views

Error that contract is not convertible to expected type address

In older solidity compilers this code snippet works. In newer compilers, I get an error. Can someone what I need to change so it works again? I get the following error message: "Type contract ...
1
vote
1answer
19 views

Calling nonpayable fallback from web3

Working on some smart contract security cases to become more comfortable with it but am running into an issue. In order to solve this particular puzzle, I need to initiate a fallback function from a ...
0
votes
1answer
33 views

Sell tokens to a contract and burn them after

The goal is to make a crowdsale smart contract where investors can buy tokens (no cap, no initial supply, all tokens are minted) and sell them to a contract for some price (rate in my case). And I ...
3
votes
3answers
213 views

Converting from bytes in 0.5.x?

I'd like to convert bytes into any other type. I.e. "0x57D80C61128d608857d5310BB514223Bb6011CAB" into the address 0x57D80C61128d608857d5310BB514223Bb6011CAB, "5" into the uint256 5 and so on. I have ...
0
votes
0answers
21 views

How to use Role-Based Access Control via Proxy?

I have a PermissionsManager contract that uses OpenZeppelin's Role-Based Access Control (RBAC) template as a base. Currently function modifiers in my app call PermissionsManager directly to check for ...
0
votes
0answers
16 views

Contract the makes other contracts race condition issue

I have a smart contract that is making two (a token and a crowdsale) other contracts. mapping (uint => myStruct) myMapping; function start(uint uuid) public returns (bool) { address ...
0
votes
3answers
32 views

Dynamically create smart contract structure based on user input

I would like to create a smart contract based on user input. User would provide some information/data from the UI, and based on the information provided my smart contract logic would get defined, and ...
0
votes
0answers
18 views

Uncaught ReferenceError: TruffleContract is not defined (Truffle Pet Shop)

I'm writing my own application that follows a similar form to the Truffle Pet Shop. I have the following code in my app.js: initContracts: function(){ $.getJSON('Greeter.json', function(data) { ...
0
votes
0answers
25 views

Can we eliminate specifying solc compiler version at the beginning of each smart contract.

Is it possible to eliminate specifying the solc compiler version at the beginning of each smart contract. This would help in separating the compiler version from the smart contract, so if the compiler ...
0
votes
2answers
22 views

Deploy ERC721 tokens to many addresses

How to I transfer many of my ERC721 tokens to many addresses? MyERC721: function mintUniqueTokenTo ( address _to, uint256 _tokenId, string _tokenURI // Store, receipient'...
1
vote
0answers
40 views

My code compiles on remix.ethereum.org but not on etherscan.io please help! [closed]

I get this error " ParserError: Function, variable, struct or modifier declaration expected. function transferFrom(address _from, address _to, uint _value) public returns (bool) ^ " everytime I ...
0
votes
1answer
28 views

Making a contract with new keyword address is always 0x0000000000000000000000000000000000000000

I'm making a contract that makes other contracts. Once the contract is made using address tokenAddress = new MyToken('Name'); I want to save the address of the contract, tokenAddress, in MyStruct. ...
2
votes
2answers
73 views

Pure functions as a replacement of constant mappings?

I need to create a lookup table [uint -> uint] that is constant. Constant mappings or switch-case are not available in solidity. Are pure functions full of if-else the only option? Any better ...
3
votes
3answers
29 views

Function that returns address if is passed or msg.sender

I'm implementing an ERC721 contract and I want to execute the following logic. This is what I want: If the user pass to a method an address, return that address, if not, return the user's address. I ...
0
votes
0answers
26 views

web3 smart contract calls to slow (arrays / lists)

I call contract like this : static async getInitialProps(res) { const users = await UsersContract.methods.getUsers().call(); const totalusers = await UsersContract.methods.getTotalUsers()....
0
votes
3answers
44 views

Using “owner = msg.sender” in a non-constructor function or in a declaration statement?

Will it be a problem to use : owner = msg.sender; statement in a non-constructor function? What if instead of writing the above code in a function, we initialize the owner at the time of ...
0
votes
1answer
16 views

Gas Estimatation

I am little confuse in the concept of Gas Estimation and price. When i add new user i get popup through metamask for the transaction amount and gas used which is totally fine. I checked my code in ...
1
vote
1answer
64 views

How does delegatecall work from Solidity 0.5.0 onwards?

I am trying, for learning purposes only, to make a mutable smart contract, but I couldn't find anything useful on stackexchange because everything I found was using pragma solidity ^0.4.x; So, I have ...
1
vote
1answer
42 views

Switch solc compiler versions

I have solc v0.5.2 on my system, but I have several contracts, that require solc < v0.5, so that I get errors: Error: Source file requires different compiler version What is the best way to run ...
2
votes
1answer
21 views

How can I call contract method that suicide and continue execution?

Can I call another contract that eventually will call selfdestruct, and keep executing my function? For example, say I have two contracts as follows: contract Destructor { address owner; ...
-1
votes
1answer
25 views

Problem with the compilation in the truffle framework

I made a smart contract in Remix-Solidity IDE, when I compiled it I had no errors and I was able to remove the contract but when I tried to use the truffle for my Dapp and compiled it it showed me ...
0
votes
1answer
79 views

TypeError: Invalid type for argument in function call. Invalid implicit conversion from contract to address requested

I am unable to use the 'this' Keyword in below code. function buyTokens(uint256 _numberOfTokens) public payable { require(msg.value == multiply(_numberOfTokens, tokenPrice)); require(...
1
vote
0answers
12 views

Compile Solidity on openbsd

i have tried several branches and all fails, has anyone got this working on openbsd? an issue has been created on github about this aswell https://github.com/ethereum/solidity/issues/5728
0
votes
1answer
38 views

Solidity 0.5.x - make address array payable

I'm trying to write a contract that uses an address[] array which should contain payable addresses. But apparently creating a payable address array doesn't work in solidity 0.5.x. All I'm trying to ...
0
votes
2answers
29 views

i am sending to an array of addresses but it is showing error on transfer function

pragma solidity ^0.4.16; contract init { address[] public userAddresses; function addStudent(address _user) public { userAddresses.push(_user); } function sendToken(uint ...
0
votes
1answer
23 views

Unable to test the value from contract using truffle test

block builders! I have trouble testing the return value from my contract, because the return uint value is always a "transaction" object (I actually don't really know what that mean) Here is the ...
2
votes
2answers
29 views

OpenZeppelin crowdsale token ownership

Using the non-modified OpenZeppelin code to create a mintable and burnable ERC20 token and a crowdsale contract, once ownership of the token is transferred to the crowdsale contract, is it possible to ...
0
votes
3answers
39 views

Contract methods calls return empty array

I'm quite stuck with this issue. It seems like it must work, but it doesn't :D Have a contract on rinkeby network which is working perfectly through remix(load by address) and truffle console. ...
1
vote
1answer
179 views

TypeError: Data location must be “memory” for return parameter public view returns (address[16]){

I know that is question has been answered in one form. However, I could not find an answer for my specific case. Here is my code: pragma solidity ^0.5.0; contract Adoption { address[16] adopters; ...
0
votes
0answers
19 views

Passing enum argument to function

So i have this enum, which is later used in struct definition in another contract. i wonder if this is a correct way to use enums in solidity? Additionally, when i run this in remix, addRight ...
0
votes
0answers
34 views

Can I use an address value in such a hash function

I have a method which updates 3 mappings in my contract. To save data I use some items properties and message sender address, which allows easily to get users data. mapping(bytes32 => uint256) ...
0
votes
1answer
22 views

Single Entrance Restriction

Please suggest that how two restric subscriber for single entry means no one can join twice. function selectionW1(address subscribersW1, uint subscriberWheelW1) public { require (...
0
votes
0answers
26 views

Unable to Call the balanceOf() function from web3 using the input wallet address

This is my web3js and html code for frontend <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=...
0
votes
1answer
24 views

Access modifiers for properties of a struct

I am relatively new to Solidity. I am following a tutorial and came up with the following contract: contract Election { struct Candidate { uint id; string name; uint voteCount; } ...
0
votes
0answers
11 views

How do I add natspec for automatically generated functions?

contract MyContract { /// @dev Total number of coins public uint256 totalSupply; } Solc automatically creates a totaSupply() function, however the natspec comment doesn't come through. How can I ...
1
vote
1answer
26 views

Return value conversion from external Call

i have an external call inside a Contract function to another function. Here is my code: Contract 1 function getContractForAddr(address ethAddress_) public payable returns (address){ return ...
1
vote
3answers
36 views

Cost-effective way to calculate final user balance based on variable events

Apologies for the title. I'm not sure what would be a more descriptive way to name this question. Assume there is a contract which has 3 potential parties. Buyers, sellers and shareholders. Buyers/...
1
vote
1answer
22 views

Pass arguments to constructor

I got a constructor like this: contract Test{ constructor(uint256 _num) public { num = _num ;} } Now I want to use this contract in another contract. Like this: contract Call{ Test test;...
0
votes
1answer
30 views

How are truffle artifacts different from ABI?

How are truffle artifacts different from ABI? Do Truffle artifacts include fields that are different from ABI that is generated using remix?
0
votes
0answers
31 views

Why was mapping introduced in Solidity instead of a dictionary or map data strcuture?

What was the thought process behind introducing mapping in Solidity? Doesn't dictionary and map serve the same purpose in other languages? I want to know the necessity that led to the inclusion of ...
0
votes
0answers
28 views

Zero balance and double entrance

I am unable to set balance to zero to all of the subscriber except the winner so that winners gets the complete pool prize and other gets zero balance. Also how can I prevent a subcriber for a double ...
0
votes
1answer
18 views

Explain “_term” Variable And What Is Slot In This Contract

This Contract for locked token in "slots??" with a term. What is term here? and what his mean with slots. And if mint locked tokens how can unlock it? contract LockSlots is ERC20Token { using ...
0
votes
1answer
65 views

web3 Uncaught TypeError: Cannot read property 'createBox' of undefined

i'm trying to create simple application by using solidity 5.0.0 , Truffle v5.0.0 and web3 web3@1.0.0-beta.34. but i've gotten Uncaught TypeError: Cannot read property 'createBox' of undefined. these ...
0
votes
1answer
25 views

Error while deploying smart contract- This contract does not implement all functions and thus cannot be created

I have written and complied a smart contract written in Solidity for token and crowdsale. Compilation was successful with no errors in Remix IDE. Here is my smart contract pragma solidity ^0.4.25; ...
0
votes
1answer
27 views

Have a connection problem with smart Contract using web3.js

Anyone that can help me in how to interact with our smartcontract using web3.js. I tried below code but this not work: This the code that I am using: if (typeof web3 !== 'undefined') { web3 = ...