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
0answers
23 views

How to send some ether to contract when trying to change the price of token?

I made an Ethereum smart contract in Solidity where a user can buy/sell/transfer tokens. In the contract, the admin can change the token price using changePrice(uint256 price) function. I want to make ...
0
votes
0answers
12 views

Remix (or any other tool): Solidity program to EVM opcode

I am interested in obtaining sequence of opcodes for a Solidity program: One example is given in the following program obtained from Link of paper I have attached the image also I need a link to a ...
0
votes
1answer
13 views

best data type for SHA256 hash

I'm trying to find a better data type for storing SHA256 hash, right now I'm using string, and I'm thinking of switching to byte32 but considering it I don't know if this is really a step in the right ...
0
votes
1answer
26 views

What is the oracle component?

I'm trying to build my own oracle for a project (so I don't use chainlink or oraclize) and I've read this https://medium.com/@robinagist/building-an-ethereum-oracle-with-web3-js-1-0-1272b59cfc31. In ...
1
vote
1answer
23 views

What does block.coinbase return when contract is being executed in a full node?

So all full nodes execute every smart contract invocation. block.coinbase is supposed to return the miners address but what does it return when the transaction is not yet in the miners hands but is ...
0
votes
0answers
20 views

Can't store the value of a math operation. It's always 0

contract MyContract { uint public priceUSD = 1.70 * 10**8; // USD uint public priceEth; ......... function setPrice(uint newPriceUSD) external ownerOnly() returns(uint, uint) { uint ...
0
votes
0answers
21 views

Unsure why my 0x transaction failed (more details inside)

I've written a simple contract tries to swap a few 0x pairs, for doing simple arbs or other 3 way trades. However, when I get the quotes from their API https://0x.org/docs/api (in serial, which takes ...
0
votes
0answers
23 views

transmit a transaction and capture an event [closed]

I am working with ethereum and I have a dapp where I use web3.js. I need to submit a transaction to the smart contract. What is the component that transmits the transaction? The node(geth, parity, ...
1
vote
1answer
16 views

Way to import library in a solidity smartcontract

I am studying smart contracts and I have looked at some popular projects on GithHub. I have seen imports like this: import "@openzeppelin/contracts/math/SafeMath.sol"; and like that: ...
0
votes
1answer
18 views

Syntax Error in Solidity Code: Found private Expected semicolon

I am trying to compile the following code: pragma solidity >=0.5.0 <0.8.0; contract AddService{ uint private _count; mapping(address=>bool) private _adders; function addByOne() ...
1
vote
1answer
27 views

when msg.sender is the owner?

how do I know if the msg.sender is the owner (the person that deployed) of the contract or a random address that interacted with the contract? in this case for example: address payable owner = ...
0
votes
0answers
8 views

toNumber in test.js

I am creating a test.js for my smart contract. I forgot to use "toNumber" while testing some uint variables to be equal in some cases and it executed without any error. So in what all cases ...
0
votes
0answers
13 views

Calculating price: “Operator / not compatible”

function getLatestPrice() public view returns (int, uint8) { ( uint80 roundID, int price, uint startedAt, uint timeStamp, uint80 answeredInRound ) = priceFeed....
0
votes
1answer
12 views

Is there a way to see events in failed transactions

Let's suppose this solidity function: function myfunction() external { emit myevent("hello"); ... revert(); } As you can see, the function fires an event. In some ...
0
votes
0answers
12 views

The data type of the return value of the solidity function has changed

As you can see, I have designed a struct in the solidity.There is a function in the solidity with the return value type User mapping(address => User) public _userInfoMap; struct User{ uint ...
0
votes
1answer
16 views

when i pass values in request transfer and call sent simple event function ,get functions are not showing any changes

pragma solidity ^0.7.0; contract peertopeer { enum State { None, Initiated, Confirmed } enum TransactionType { Unknown, Deposit, Withdrawal } uint toyprice; struct ...
0
votes
0answers
28 views

when i try to pass values for the function i am getting error [closed]

function requestTransfer(uint fromAccount, address seller, uint toAccount, uint amount, TransactionType transactionType) public{ if (transactionType == TransactionType.Unknown) return; ...
1
vote
0answers
15 views

Debugging contracts on a mainnet fork with Remix

I'm developing a contract that relies on some states of other contracts currently deployed on mainnet. I'm after a way to test and debug my contract without having to deploy to mainnet first. I'm ...
0
votes
1answer
26 views

Old contracts data not visible if pushed new contracts?

I created a contract campaign and deployed this contract in infura , then I called some functions of the contract which created the subsequent data(as in list of ongoing campaigns) in blockchain. In ...
0
votes
1answer
13 views

how to resolve return argument implicitly convertible to expected type address

function getFrom(bytes32 transferId)public returns (address ) { Transfer memory transfer = transfers[transferId]; if (msg.sender != transfer.to && msg.sender != transfer.from) ...
0
votes
0answers
34 views

Please help, can't call addLiquidityETH() function from Uniswap on my contract

I'm a newbie, have been learning solidity for 6 months now. I have been trying to fix this problem for couple of months but still got no hope. I'm trying to learn how to add liquidity to uniswap by ...
0
votes
0answers
24 views

String to float maintaining decimal places

I've seen some thread already however I haven't found anywhere a way of converting a string number to float number and maintaining the decimals. ie "27.546" to 27.546
0
votes
1answer
16 views

mapping not updated

I'm testing a very primitive contract using mapping. contract PhysicalContract { uint numContracts; mapping (address => uint) contracts_test; function newDeal(address adr, ...
0
votes
1answer
12 views

What is wrong in require()?

The voter can be registered only once but the code below registers more than one voter with same address struct Voter { string name; uint8 age; bool voted; address voterID;...
1
vote
1answer
26 views

How to use compiler version 0.4.17?

I am using solidity extension by Juan Blanco. pragma solidity ^0.4.17; contract Inbox { string public message; constructor(string initialMessage) public { message = ...
1
vote
1answer
11 views

Can block.timestamp value change during execution?

I'm facing a doubt while developing an Smart Contract. I was getting current date from block.timestamp several times inside a function. Could this value change during an Smart Contract execution? Or ...
0
votes
2answers
29 views

How to I initialise an array inside the contructor in solidity?

I'm using the remix IDE.I want to define the size of the array at the time constructor is called. Someone please help. This is what I tried : pragma solidity >=0.7.0 <0.8.0; contract Vote { ...
0
votes
1answer
31 views

Declare an string array inside a int array in Solidity

I am using truffle and I am trying to pass during the deployment execution script a double array of prices inside my contract's constructor. ie In the migration file I have a 2 dimensional array. It's ...
0
votes
0answers
8 views

How can I generate hash of string received from function argument

I want to generate hash of string received through function argument. Sha256 require bytes in argument. How can I convert and then save hash in _hash variable. struct ORGANIZATION{ bytes32 hash; ...
1
vote
1answer
12 views

How to return a ENUM in string instead of integer

A State is defined and function to return state in smart contract: enum State { ForSale, SellerDelisted, BuyerCancelled, BidPlaced, DepositMade, InDispute, Complete } State public state; function ...
0
votes
0answers
33 views

What's wrong with my buyToken function?

Here is my solidity interface IERC20 { function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external ...
0
votes
0answers
25 views

ERC1155 per token variables

I want to create an NFT that can mint different character types and multiple clones of each type. The clones within each type will start with same metadata, but each individual token should have its ...
0
votes
0answers
24 views

Solidity external call with bytes4 / keccak256

I want to call a Contract1's function from Contract2. I know the way i've tried is deprecated, but i want to understand. This is why i've set a very old solidity version with the pragma directive. I ...
1
vote
1answer
35 views

Why is there 2 methods abi.encode and abi.encodePacked for argument encoding

When we call a function on an external contract, the evm computes a bytes buffer which contains the function signature and arguments. There are 2 ways to serialize arguments: abi.encode and abi....
0
votes
0answers
9 views

how to pass fix size array via interface in solidity 0.4.25

I used the following code interface test{ function testfunction(uint[20] memory P, uint[20] memory Q) external returns(uint,bool,uint); } It gives the error Location has to be calldata for external ...
1
vote
1answer
13 views

Before a transferFrom, is it better to check the allowance first?

transferFrom already checks the allowance, so does it make sense?
0
votes
0answers
12 views

Arrays not showing up inside structures

I am creating a record of people and have created a structure struct asset{ uint assetId; string hash; address creatorAddress; uint cost; uint soldCount; } struct person{ uint ...
0
votes
0answers
12 views

Deploying ERC20 Error

I'd like to deploy follow "StandardERC20" token to kovan test net using Truffle. I want to deploy same contract like "https://etherscan.io/address/...
0
votes
1answer
18 views

Estimate Solidity function gas cost

When i deploy a smartcontract with remix, i can call functions in order to test it. I do not really know if this is remix or metamask which is doing this job: Before validating the transaction, i have ...
1
vote
1answer
20 views

Is there a solution to implement this scenario? [closed]

Suppose a user1 in a network wants to change data in a smart contract function, but before this transaction is pushed to the chain the other participants of the network receives a notification saying ...
0
votes
0answers
12 views

How can I compile multiple smart contracts in a single compile.js file?

There is another post on this question but I don't find it useful enough so I thought I should ask again. In my compile.js file, I'm taking each smart contract's complied code and put it in a ...
1
vote
0answers
31 views

What does sendSignedTransaction return?

I want to call a method in the smart contract (UpdateWeather) that goes through several steps before returning the result (an integer). I use sendSingendTransaction but I have doubts. Is the ...
0
votes
1answer
25 views

Contract pays for gas

Is there anything solidity in line that would let a contract with ETH assigned to, to pay gas. Say I want something simple. contract whatever { uint256 one; uint256 two; function execute() public { ...
0
votes
0answers
19 views

The allowence does not show the approved value with ERC20 token

An ERC20 contract was deployed in remix and here is the approve console output: status true Transaction mined and execution succeed transaction hash ...
1
vote
2answers
23 views

Can a smartcontract offer free gas

I have wrote a smartcontract which will be called by a mobile device. This device will be outside. It embbed a software wallet (private key). But this wallet will own 0 ether because the device can be ...
5
votes
1answer
19 views

Why do Solidity audits include checks that function address arguments are not equal to 0x0?

I've recently completed an audit for some Solidity contracts, and one of the checks the auditor included for all of the contracts was to make sure that address function arguments are not equal to the ...
1
vote
0answers
71 views

Why is the allowance 10**8 inside the test but equal to zero in the smart contract?

I'm running this test: def test_mint(prf, exValue, web3): wBtcAddress = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" ABI = [{"constant":True,"inputs":[],"...
2
votes
1answer
22 views

73: TypeError: “send” and “transfer” are only available for objects of type “address payable”

This is my simple code for following along a tutorial. We are building a Lottery Smart Contract. However, I am failing to transfer the contract's balance to the winner. (see the last line inside of ...
1
vote
0answers
26 views

Internal Transactions - How to find out the address of the contract that is calling?

i have been Googling for this answer, but i haven`t succeeded. The scenario is the following: I have two contracts interacting with each other, and I want to make sure that they only respond to each ...
1
vote
1answer
33 views

Who owns the ERC-20 tokens? [closed]

I am creating an Erc-20 token. I want to know whether the token will be owned by the smart contract at the contract's address or by me, the contract-deployer at my address? I want to know this because ...