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

How to use Ganache, Remix IDE, MetaMask, and Web3js without Truffle

I am having an issue migrating a contract using Oraclize API to Ganache from Truffle. However, everything is working fine when running the contract from Remix IDE via MetaMask. As I want to write the ...
0
votes
1answer
12 views

What is the proper pattern to use a temporary variable and ensure it gets stored?

A contract has a state variable, which is complex. For the example, lets say it is a mapping of structs. Inside a method, I want to access that and store the changes. Like so: contract FooManager { ...
2
votes
1answer
20 views

Is there Metaprogramming in Ethereum

I am curious to know if there is a way to do metaprogramming in Solidity. My use case is about generating a smart contract from user inputted data.
1
vote
1answer
11 views

Can't call a function in a contract, returning something from another contract

I use private geth + web3js (in truffle this works good) Here is an example worked as expected: the first contract: pragma solidity ^0.4.24; import "./Second.sol"; contract First { Second ...
0
votes
1answer
30 views

Some basic problem about Smart Contract

I just started learning how to write smart contracts. I have some questions about crowdfunding.I follow the instructions of my textbook. My operating system is Windows 10. It compiles OK, but when I ...
0
votes
1answer
12 views

Using the same event name in different contracts

Suppose I have two different contracts, and I implement an event in each one of them. If I use the same event name in both contracts, will it make it more difficult (or even impossible) to filter the ...
0
votes
0answers
8 views

Send function transaction to existing smart contract using web3j

I've been exploring web3j and got the credentials working so I'm able to send transactions from an ethereum address. Now I want to send a transaction to an already existing smart contract and use a ...
0
votes
2answers
20 views

Type of the “var” variable for structs

I have the following line of code in Solidity: var res = result.toSlice(); This slices a string. When trying to compile in Truffle, I am getting var is deprecated error message. I am confused a bit,...
0
votes
0answers
7 views

Probleme with updating struct through payable call with web3js. But works through remix

I have a function in my contract to which I want to send wei to, the contract should update the value in a struct and transfer the value to another address. Solidity code: function voteMeme(uint ...
1
vote
1answer
18 views

How do you implement a “Micropayment Channel” in a Dapp?

I've come acrossed an article, Signing and Verifying Messages in Ethereum, where it says that you can pay for other user's gas transactions but so far I haven't seen any implementation or tutorial on ...
0
votes
1answer
19 views

Call a smart contract function when condition met

I am currently developing a smart contract with several states: enum State {created, accepted, over} Depending on the state, users are allowed to perform different action. What I would like to do, ...
0
votes
0answers
12 views

Invoking the smart contract [duplicate]

how can i tell the EVM that only a few accounts in the network can invoke my smart contract.. for example in voting solidity code i want only a few accounts of my network to cast their vote.
0
votes
0answers
14 views

Issue with setting up web3 js connection with multiple ethereum nodes

I have setup an Ethereum network with 2 nodes - A and B. I deployed a contract on both the nodes. What the contract does - mapping(uint=>string) Record; function addRecord(uint id, string ...
0
votes
0answers
15 views

Updating the tx hash

Following is a snippet of my code (which is working) .... let txhash = ''; class App extends Component { .... }; async componentDidMount() { ..... } onSubmit = async (event) => { event....
1
vote
1answer
22 views

I want to remove the timed aspect of this crowdsale contract and make it finalizable manually [on hold]

Which lines do I remove and what do I replace them with to change this from a timed crowdsale contract into one I can end manually? pragma solidity ^0.4.18; interface token { function transfer(...
0
votes
1answer
12 views

Truffle test error: deducts the amount from the allowance

What i did first was watching at Dapp university tutorials, I manage to watch all 14 videos and run it with Ganache. But since everything is doing good at local, I created my own private network. Then....
0
votes
1answer
29 views

How to state private keys when using node.js and ethereum to run a contract?

I have to run node.js to execute smart contracts. My quetsion is about the keys. I have seen this from the docs - 1. Code to sign 2. Code to execute But I am unsure how the two are combined. Could ...
0
votes
1answer
23 views

Deploying using Rinkeby understanding

Deploy we are using truffle truffle migrate --reset --compile-all --network rinkeby when i am deploying i will be getting build folder in my project directory while deploying through the ...
-1
votes
1answer
20 views

I have a problem with my crowdsale it doesn't work with 8 decimals [on hold]

Crowdsale external : https://kovan.etherscan.io/address/0xd7d36ea522a3abcc6001d6cd31fc98f254db18ac I have a problem with my code in solidity. This code works with 18 decimals, but with 8 decimal it ...
1
vote
1answer
15 views

AssertionError: cannot transfer value larger than approved amount

I have followed the tutorials of Dapp University. Using Ganache and Metamask 127.0.0.1:7545 and did a truffle test or migrate it works perfectly. Result: Then, I change my network this is my truffle....
1
vote
1answer
14 views

AssertionError: error message must contain revert

I have tried a lot of research. I still somehow can't find and understand why this error occurs when im in private network. But if in 127.0.0.1:7545 which ganache, everything seems to be working, all ...
0
votes
0answers
11 views

not able to test smart contract

I am getting this error when testing my smart contract. sometimes I am getting this error and sometimes its working fine "before all" hook: prepare suite: Uncaught Error: VM Exception while ...
0
votes
0answers
12 views

what does memory[0x00:0x00] means?

I see a pseudocode : memory[temp3:temp3 + 0x00] = address(temp0).call.gas(!temp4 * 0x08fc).value(temp4)(memory[temp3:temp3 + 0x00]); what is the memory[temp3:temp3 + 0x00] means? I just know like ...
0
votes
1answer
27 views

How to fix “No events were emitted”

I have been following the instructions in the Dapp university tutorial. But I am using Windows 10, Dapp University is Mac. I downloaded this truffle with smart contract ERC20 from Dapp university. ...
0
votes
2answers
15 views

solidity split each number

uint number = uint(keccak256(abi.encodePacked(now)) Split each number. For example, if the value of number is 1562, I need to be able to extract the result as: uint a = 1, uint b = 5 , uint c = 6, ...
0
votes
1answer
8 views

Add Custom Data to ERC20 token transfer

I'm in a situation to implement the following scenario, Need to transfer ERC20 standard token(own by my contract) to some another wallet. When recording transaction on Ethereum, need to add custom ...
1
vote
0answers
10 views

Not able to Get the response from the function call from Node Js Service Using Web3@1.0.0-beta.36

I am deploying two contracts A and B using Web3(1.0) and solc. My Solidity file looks something like this: pragma solidity ^0.4.21; contract A { uint public value; constructor(uint newValue) ...
0
votes
2answers
10 views

Oraclize: Mismatching queryId and myid

I have the following contract that uses Oraclize: contract Test is usingOraclize { bytes32 public query; mapping (bytes32=> address) senderAddress; address public resultAddress; function ...
0
votes
2answers
22 views

Solidity: How to initialize an array within a struct, passed as a parameter?

pragma solidity 0.4.25; contract A{ struct N{ string any; uint256[] numberArray; } N[] public numbers; function init(uint256[] _numbers) public{ for (uint256 ...
0
votes
1answer
17 views

i want get random number between 100-999, as follows

function random() internal returns (uint) { uint random = uint(keccak256(now, msg.sender, nonce)) % 1000; nonce++; return random; } In this way, you can generate random numbers, but there ...
0
votes
1answer
20 views

promise chaining in test.js file

it("should throw an exception if you try to buy an article that does not exist", function() { return ChainList.deployed().then(function(instance) { chainListInstance = instance; ...
1
vote
1answer
19 views

Getting and storing address of erc20 contract after dynamically creating it

I have a function which dynamically creates an ERC20 contract on calling a function in another contract as follows: function createDao(string _tokenName) public payable { tokenNumberIndex = ...
1
vote
1answer
14 views

Discrepancy in Solidity compiler output for Remix and offline (same version, same code)

I'm compiling the following contract locally and on Remix and getting two different bytecode results. Contract pragma solidity ^0.4.25; contract ReadBool { bool public flag; function ...
0
votes
1answer
19 views

Reading of state variables vs the memory varables . and memory vs storage keywords

contract Shopping { struct Article { uint id; address seller; address buyer; string name; string description; uint256 price; } // state ...
1
vote
0answers
29 views

Using oraclize and solidity-util - having trouble splitting string separated by space

I am learning to use Oraclize to connect it to random.org to generate random numbers. Here's my test contract code: pragma solidity ^0.4.25; import "github.com/oraclize/ethereum-api/oraclizeAPI.sol"...
0
votes
1answer
33 views

Error while executing solidity contract from web3 client

I have a contract as follows - contract getSchwifty { string internal constant seeWhatYouGot = "I want to see what you got!"; string internal contestResult; mapping(uint=>string) Record; ...
-1
votes
0answers
14 views

Help me code callback external [on hold]

Help me. Example im creator contract and Im create token, and create subcontract tokensale external. If want to buy, send the subcontract, and why if I want to callback token from subcontract to ...
1
vote
1answer
23 views

Unit test in truffle fails

pragma solidity ^0.4.23; contract adding{ uint256 public total; function add(uint256 val1,uint256 val2) public returns(uint256){ total = val1+val2; return total; } } The above code ...
1
vote
1answer
22 views

Calling and funding a payable function from existing contract balance [duplicate]

If smart contract A has a balance of 1 ETH, can I call a payable function on Contract B, from a function in Contract A, with a msg.value that would be effectively withdrawn from the balance of smart ...
0
votes
1answer
14 views

Changing the contract state while waiting for the Oraclize __callback()

I have a contract that uses Oraclize to query some data. When the query is sent, a global variable address is set to the msg.sender. This is to be able to interact with the query sender in the ...
0
votes
1answer
20 views

Is data inputted as a parameter for a smart contract function visible?

Let's say I have something like this: bytes32 person; function registerPerson(address _person) public { bytes32 x; x = sha256(abi.encodePacked(_person)); person = x; } For privacy reasons, ...
0
votes
0answers
20 views

Getting error while compiling solidity code using command line and a script

I am following a video tutorial. Here I am trying to compile a solidity code using a JS script and a node comand (node compile.js) But getting following error. Please kindly help. Thanks in advance.
1
vote
1answer
24 views

Defining the transaction object for offline transaction signing using “web3.js from the broswer”

I am trying to call a contract method ( a write operation ) and sign the transaction manually using my privatekey. The transaction hash is being generated but when I go to etherscan, the transaction ...
0
votes
2answers
30 views

Intracting with dapp using frontend truffle petbox

App = { web3Provider: null, contracts: {}, account: '0x0', init: function() { // Load pets. return App.initWeb3(); }, initWeb3: function() { if (typeof web3 !== 'undefined') {...
0
votes
1answer
16 views

Is there any gas cost when executing `msg.sender.transfer(0)`?

I have a function which looks more or less like this: function exchange(uint256 amount, bool specialCase) external returns (uint256) { let retVal; if (specialCase) { register(amount); ...
0
votes
1answer
25 views

Problem getting data from a different deployed contract - Solidity

I've been working on the cryptozombies tutorial and now i want to go further but when trying to deploy the contract on REMIX to test it i'm having problems. I get: transact to ZombieFeeding....
0
votes
2answers
42 views

What difference between if and require in solidity

if(_newDelegate != delegateContract){ // Do something } require(_newDelegate != delegateContract){ // Do something } Could anyone explain difference between if and require in solidity? ...
0
votes
1answer
26 views

Retrieve and store data into a local database using smart contract

For my information oraclize can be use to retrieve data from several data source but what if i need to get from a local database such as oracle,sql, etc. Is there any way of doing it? PS: I am ...
0
votes
3answers
28 views

Gas cost call vs send for pure/view functions

I'm aware of the fact that pure/view functions cost no gas with a simple "call". But what happens if i have a function that changes the contract state based on the pure/view function result. Do i have ...
0
votes
2answers
27 views

Comparing the array of numbers in Solidity

I have the following array of numbers: 1. [2, 4, 6, 8] 2. [4, 2, 5, 7] I need to check whether or not each number of the first array is included in the second array. In that case, a function needs ...