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
21 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
25 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
14 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
33 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
26 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
16 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
13 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
15 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
24 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
15 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
21 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
16 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
17 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
28 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
15 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
30 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
34 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
30 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
13 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
27 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 ...
0
votes
0answers
7 views

Solidity OpenZeppelin ERC1155 how to check extra content in smartcontract [e.g. opensea]?

Hello I have tokenBalance in my solidity contract. How can I check value of its unlockable content, if there is any? I read I have to use Unlock.sol library, but nothing more valuable I found.
0
votes
2answers
25 views

Solidity OpenZeppelin get balanceOf() erc1155 token from given address

I was looking for simple implementation of checking balanceOf ERC1155 with given _tokenId using openzeppelin library but I haven't found any. Please Help me how can I use this method in smartcontract ...
0
votes
0answers
26 views

What is the best way to check if a value mapped to an address is smaller than something?

I have a simple mapping of an address mapped to a value. I need to be able to see if any value associated with an address is smaller than a given value. What would be the best way of doing this. I ...
0
votes
1answer
23 views

How to convert uint8 to uint256 bitmap in solidity?

Say I have a uint8 with binary value 0000_1001 i.e. 8+1=9 in decimal. How do I convert this uint8 in a gas efficient way to a uint256 which represents a bitmap?, such that in this example the 9th bit(...
0
votes
1answer
16 views

How to declare getter function signature in interface for a mapping?

I have a contract that implements an interface, the contract has a state variable mapping(address => bytes32[]) public usersLists, I defined a getter function signature in the interface for this ...
0
votes
1answer
10 views

Why hardcoding wallet addresses into the code of contract considered bad?

Why hardcoding wallet addresses into the code of contract considered bad? And what is the workaround for that? I've not found any information in the Internet.
0
votes
1answer
35 views

How to get MethodID of a function in a smart contract?

If I look in the past transactions of a smart contract that called a function, I can see the MethodID being used. If the function was never used in the past, I would never know what was the method ID....
1
vote
2answers
79 views

Is it possible to make a static call to a non-static function from within a smart contract without changing blockchain state?

Ive seen that the web interface from Uniswap is making a "fake" call to the contract holding the liquidity positions, and claims all fees (.collect(..)) without actually claiming them. ...
0
votes
0answers
44 views

How to get the nfts in a user wallet address

I am currently working on an nft marketplace and each user has a dashboard and a profile page. And on both pages I would like to get the list of nfts a user has listed, sold and owns. Currently I have ...
0
votes
2answers
48 views

How to correctly call `<address>.balance(uint256)` to get the balance of a specific address [duplicate]

I am a newbie in Solidity. I am learning by reading official docs, i.e. Solidity I am trying to get the balance of an address in solidity using the simple balance method. Below is my code: pragma ...
0
votes
1answer
37 views

How to add NFT Royalties Feature to a marketplace

I'm currently working on an NFT marketplace, and I would like for creators to be able to add a certain percentage as royalties for future sales like rarible does. So what I wanna know is do I add this ...
1
vote
1answer
27 views

How to correctly import aave/flashloan-box in Remix IDE

I was following the step-by-step guide, and since there is only the main code, I've tried with the following imports pragma solidity 0.6.12; import { FlashLoanReceiverBase } from "https://...
0
votes
1answer
40 views

How to successfully utilise the safe mint or mint function?

function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an ...
0
votes
0answers
17 views

Restricting contract deployment on a private eth fork

I have a private fork of the ETH blockchain and I'd like to modify the source to allow deploying contracts from a single address only using this answer. The caveat, however, is that instead of a ...
0
votes
1answer
18 views

Using transfer function always exceeds balance, or allowance!

I've been struggling with transfer function, where approval is not needed on ERC20 tokens where the caller is msg.sender as it's a public function, but I'm always getting same error.. Indeed I am on ...
0
votes
1answer
36 views

How to call a contract function from ReactJS, that takes a struct as an argument?

I am struggling to figure out how to actually call a function (using React) in a contract that takes a struct as an argument (which also has another struct in it) ? The contract function looks like ...
0
votes
1answer
13 views

Chainlink - where are adapter keywords specified?

I watched a tutorial video here. In the following example, we use req.addInt("times", 100); Where are the adapter references specified (in this case, "times")? On market.link, I'm ...
0
votes
1answer
26 views

Getting data into a contract from an API that requires authentication

I'm trying to pull data into my smart contract from an API using the approach described here: https://docs.chain.link/docs/make-a-http-get-request/ I can get the example code at that link working just ...
3
votes
2answers
178 views

NFT royalties with solidity smart contracts

I hope you are all well. Do you know how NFT royalties work with solidity smart contracts?? Or do you know a tutorial about it? Thank you Take care Pierre
1
vote
1answer
23 views

How are contracts allowed to transfer ERC20 tokens from a different contract?

Sorry if my question sounds a bit vague, but I'm looking at writing an NFT staking contract that will allow holders of the ERC721 token to transfer those tokens in return for our ERC20 token. There ...
0
votes
1answer
38 views

How to copy all items of an array to a dynamic array of a different size?

I have a problem when I try to store an array in another array. I get as error when running store: transact to MyContract.store errored: VM error: revert. I need the second array, because in the next ...
0
votes
1answer
24 views

Why am I getting "not implicitly convertible" and "member not found" errors when trying to use TokenTimelock?

I am rewriting some code in order to be able to set 4 timelocks from a fixed date to team members. I always get the error ~/code/ANCToken$ truffle compile Compiling your contracts... ================...
0
votes
1answer
16 views

How to be sure registered array/queue are always the same?

I'm trying to a smart-contract where user can register himself (in an sorted array) and when a amount of people is registered (here 2) a Battle is created and firsts registered users battle each other....
0
votes
1answer
10 views

Could not find a declaration file for module 'solc' [duplicate]

i found that "const solc = require('solc');" is returning an error which says Could not find a declaration file for module 'solc'. PLEASE HELP

1
3 4
5
6 7
256