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

Fullfill randomness type error when Importing chainlink functions

Trying to inherit the randomness functions into my main contract(lottery). Getting a type error and I can't work out why. Tried all sorts. Is there a better way to inherit or import chainlink ...
0
votes
1answer
27 views

Smart contract funds stuck

Is there any possibility to withdraw ether from crowdsale contract? 0x6c725F41E98451F167820551013BD2f5BE8bFE6f I had also "pre-sale like" contract has MyToken in it ...
0
votes
1answer
24 views

How to make a physical asset an NFT

I am trying to create an NFT but with physical assets, how can I make this work.
0
votes
2answers
20 views

Update arbitrary contract state variable

I have this contract with dozen of variables contract Test { uint256 public a = 1337; uint256 public b = 9001; string public c = "abc"; string public d = "xyz"; bool ...
0
votes
0answers
20 views

How to approve a contract address as sender?

Based on this official example of token swap: https://solidity-by-example.org/app/erc20/ If my token dont have an initial supply... How could to approve the contract address as sender to mint token ...
0
votes
1answer
12 views

Walletconnect integration not working on mobile

This is a weird one. I have successfully integrated walletconnect on my Dapp for the first time and it works just fine on my pc. When I try accessing it on my phone, it doesn't work. I am trying a ...
0
votes
1answer
16 views

Adding whitelist batch function

So for my project I want to add a function that allows me to add multiple addresses and assign a name to those addresses that will be later used for minting their NFTs. This function takes in an array ...
0
votes
0answers
24 views

ABI.DECODE multiple swap data from 1inch

hello im trying make function for swapping multipple times in 1 function and i want input params this way that in python i encode them and inside function i decode some parameters(so function will ...
0
votes
1answer
15 views

Are multiple interfaces with same function signature necessary

I need some basic interface understanding. In my contract I implement two interfaces with the same function signature: interface IFirst {function someCall(address sender) external;} interface ISecond {...
1
vote
0answers
19 views

(Update Solidity ^0.8.0) How to check string length? [duplicate]

There is a question about this from four years ago. One answer suggests using bytes(str).length, which still works as described, as an estimate that potentially overestimates the number of characters. ...
0
votes
0answers
8 views

How to verify polygon smart contract using truffle?

I deployed a simple NFT smart contract on polygon mumbai testnet but when I am trying to verify it then It is showing an error. please guide me how to verify it... This is the error which I am getting ...
0
votes
0answers
16 views

Revert transaction payable error with abi.encodeWithSignature

I have two contracts: Validate.sol // SPDX-License-Identifier: MIT pragma solidity 0.8.4; contract Validate { function validate(address _verifier, bytes memory _validityData) public view { ...
0
votes
0answers
10 views

Two external/public functions calling a private function. Where to put nonReentrant()?

I have a case similar to those examples bellow. Assuming buy() & discountBuy() has no call, transfer or send, would it be safe to let the nonReentrant() in the private _internalBuy()? It seems to ...
0
votes
1answer
9 views

What does % mean in Solidity?

Im learning solidity through cryptozombies.io and the first lesson ive come across this 83 % 7 + 1 = 7, does this mean that the floor division of 83 by 7 + 1 is equal to 7?
0
votes
1answer
10 views

How to extract fourbyte signatures and resulting arguments from Solidity compiler output?

It seems that the Solidity compiler output has JSON that lists methods and their arguments as a complex nested JSON structure. How can I take parse structure and output the string and fourbyte that ...
0
votes
0answers
19 views

How To Calculate the Exact Amount Of Tokens Out One Would Receive when using Pancake Swap SDK

When Using Pancake Swap SDK The Following Function const exactOut = new Trade.bestTradeExactOut( [pair_0_1], token0, new TokenAmount(token1, parseFloat(amountOut....
0
votes
1answer
20 views

withdraw function for withdraw ethereum token from a contract is behaving weird

I copy a withdrawal function from the solidity documentation and added it to my contract function withdraw() public onlyOwner { uint256 ownerBalance = address(this).balance; require(...
0
votes
1answer
12 views

I cant send eth from a smart contract to an address

Im trying to send eth from a smart contract to an address but it sends it from msg.sender to smart contract address.Here are my functions receive() external payable {} function close(address payable ...
0
votes
1answer
22 views

Is the gas cost for constant and immutable about equal?

According to this question the Solidity 0.5.0 Compiler cannot compute a constant state variable that invokes a function, however I'm also experiencing this issue on Solidity 0.8.10 using the ...
0
votes
1answer
10 views

Passing object vs address in solidity functions?

I'm trying to understand if there is any difference between passing an object vs passing the address and casting. For example: function getTotalSupply(IERC20 token) view returns (uint256) { return ...
0
votes
0answers
5 views

Ethereum app looking at wrong Address from Migrations.json

I developed a webapp for ICO's (KOVAN TESTNET). It works just fine locally but when I push the files to my live site, it uses a different address for my sales contract. it is fine for my token ...
0
votes
1answer
16 views

How to handle division by zero in solidity?

In popular programming languages dividing by zero results in an exception being thrown such as ZeroDivisionError in python. Does solidity allow for such exception handling? and if so how would I ...
0
votes
1answer
17 views

How much damage could result from a user wallet interacting with a malicious smart contract without approving token allowance first

Let's assume that a user found themselves interacting with a malicious smart contract, either in the form of a custom smart contract or as a malicious ERC20 or ERC721 token that was sent to their ...
0
votes
2answers
16 views

Invalid number of parameters for "undefined". Got 0 expected 1!

I'm new to solidity I'm trying to create an ERC20 token. I get this error when I try to deploy it "CorepassToken" -- Invalid number of parameters for "undefined". Got 0 expected 1!...
0
votes
0answers
17 views

Why am I getting the "not recognized as an internal or external command" error when I run truffle unbox on Windows?

I'm getting this error running trufflesuit unbox react: Starting unbox... ================= √ Preparing to download box √ Downloading 'files\solidity\web\frontend\client\node_modules\.bin\' is not ...
0
votes
1answer
23 views

solidity interface - Contracts calling unimplemented functions

I'm new to solidity and OOP. I'm trying to understand the code in this simple lottery game example: https://github.com/alphachainio/chainlink-lottery/blob/master/ethereum/contracts/ I am confused when ...
0
votes
1answer
13 views

Does typecasting create a new copy with it's own memory?

Consider the following two snippets. bytes memory a = bytes(someThing) and bytes memory a = new bytes(sizeOfSomething) a = someThing What's the difference? And also, what's the correct way to ...
0
votes
0answers
28 views

How to implement two-way conversion between an on-chain token and off-chain in-game currency?

I need some help to code an in-game currency for my game. Explaining: I need to swap a token to an in-game currency (off-chain), and later transform the in-game currency into on-chain tokens. It's ...
0
votes
1answer
24 views

Cannot retrieve uint Array from Struct in Solidity

I have the following struct in my contract struct Transaction { TransactionType transactionType; uint256 id; uint256 productId; uint256 timestamp; address from; address to; ...
0
votes
2answers
13 views

Excluding an address from fees in _transfer function

I intend to exclude the deployer of the contract from paying a 9% fee, which is placed on every transfer. I tried to do this by adding a if statement to _transfer that checks if the sender has the ...
0
votes
0answers
12 views

Understanding ERC721._checkOnERC721Received in openzeppelin library

When you use OpenZeppelin's ERC721 implementation, in most cases you call _safeMint function. _safeMint does some obvious basic operations except this one: require( _checkOnERC721Received(address(...
1
vote
1answer
14 views

Correlation between order of txs in the same block and nonce

I found position index referring the order of txs within a block. Txs are executed in order from position 1 to the end. Is there any correlation btw the position(order of txs) and the nonce of txs? ...
0
votes
0answers
19 views

NFT Contract not showing the token value

I am trying to create a NFT token by using the openzeppelin and chainlink. Everything works fine from compile to migrate. But when i try to check my contract https://rinkeby.etherscan.io/address/...
0
votes
0answers
8 views

Error returning a struct

I'm taking this free course on freecodecamp and as I was trying to follow along with the code I got stuck on this code. After I deploy that contract it's supposed to implement the person struct but ...
0
votes
1answer
11 views

How do I find the code of a external interface function?

I am learning about importing contracts and noticed with the following contract there is an external interface function with no code block. Where does this code come from? function version() external ...
0
votes
1answer
20 views

How to convert between uint256[] and uint256[x]

Basically, I want to call a function myfunct(uint256[] memory) but I have a uint256[13] I have the uint256[13] because I want to temporarily store uint256s in a function, and save memory--not do ...
0
votes
1answer
15 views

What am i doing wrong, the code compile, but when i call the create donation function i get invalid opcode. in solidity 0.6.0 everything runs well

//SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; contract Donations { struct Donors { uint amount; address donorAddress; } struct NewDonation { string Name; uint ...
0
votes
2answers
16 views

How to create your own Mock contract if one does not exist

Is there a guide on how to create your own Mock contracts in order to properly test smart contracts on local network? And how to conclude if one corresponds to the idea, and meets the requirements of ...
0
votes
1answer
23 views

Multiple ways to check the balance of ERC20 tokens of smart contract: which to use?

I have a smart contract which holds ERC20 tokens. There's a function in it, in which I need to check whether the smart contract has enough balance, and if so, send out some tokens to a user. I thought ...
0
votes
0answers
13 views

modifying _transfer function to have a tax

I want to add a 9% tax on every transfer, the tax is sent to the deployer address. I'm trying to do this via overriding the _transfer function. However, I get declaration errors whenever I'm trying to ...
0
votes
0answers
5 views

Unable to create logs / events with simple smart contract using truffle develop

I'm wondering why I am unable to generate an event that logs data to the tx using truffle develop with the below smart contract. When I try to log the logs, I am getting an empty array. SmartContract /...
1
vote
0answers
28 views

What are the best practices when launching a smart contract protocol on multiple networks/chains?

Hi I have some questions on protocols that launch on multiple networks/chains. For example, Aave originally launched on the Ethereum network but now is also on networks like Polygon and Avalanche. To ...
0
votes
1answer
31 views

What could go wrong if I change the version pragma of a third-party contract to make it importable with a newer Solidity compiler?

What are the consequences of changing compiler versions in dependency contracts to the same version as the main contract? I have one main contract that inherits some other contracts to interact with ...
0
votes
0answers
25 views

Check that the sender of NFTs is the owner of the IERC1155Receiver contract

I'm currently building a smart contract in solidity (v0.8.6) that can store NFTs, but I only want the owner of said contract to be able to send NFTs to it. The onERC1155Received function gives several ...
0
votes
1answer
14 views

Contract reverts when making calls to erc20 token contract from my contract

i have this basic contract that should work, but it keeps reverting because of the approve call in the constructor, i also notice transferFrom calls from my contract also fails after manually ...
0
votes
0answers
3 views

The sum of total holders on bsc scan is short of total supply()

I have a BSC token, it has a total supply of 1 trillion tokens. It’s a BEP20 token and uses compiler 0.8.9 and OpenZeppelin contracts. I did a few trades (it’s a safemoon-style auto liquidity, with ...
0
votes
1answer
11 views

python-dotenv fails to import PRIVATE_KEY from .env file: "Cannot convert None of type <class 'NoneType'> to bytes"

I am learning solidity and when I use python-dotenv to import my PRIVATE_KEY from a .env file, export PRIVATE_KEY = 0xd6a5ea3d2c97b1dd03fd1b9c447e36791522135136665f23b0c08c6395f66d7a it imports it as ...
0
votes
2answers
26 views

Better way to retrieve the values of all public state variables of a Solidity contract

My solidity "0.7.0" contract pragma solidity ^0.7.0; contract DoubleEscrowTrade { uint256 private locked = 2; //2: unlocked, 1: locked. uint256 is gas efficient than bool uint256 ...
0
votes
0answers
13 views

How to import deployed contact on public testnet into remix [duplicate]

I see that there are lots of information on how to deploy your contact to rinkbey using remix but not vice versa. I want to copy deployed contact from rinkbey testnet to local Blockchain simulator ...
1
vote
1answer
18 views

Why doesn't Truffle's testing framework automatically retrieve fresh values of public state variables after every interaction with the contract?

I have the following simple smart contract defined: contract LoanApplication { struct Applicant { bytes32 ssn; bool hasApplied; } struct Loan { string loanID; uint ...