Questions tagged [function]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 views

Is there a decentralized version of Cloudflare Workers?

Is there a decentralized version of Cloudflare Workers or some comparable service like AWS Lambda functions or GCP Cloud Functions? I would love a blockchain based, or just a decentralized version of ...
0 votes
0 answers
10 views

Fuction type assined as as variable to another func name

So, here is a code snippet: function stake ( AssetType _assetType, uint256 _timelockId, uint256, uint256, uint256 ) external nonReentrant { ...
1 vote
1 answer
14 views

What is Solidity's equivalent of raw_call()?

I'm wondering, does Solidity also have a raw_call() function like Vyper which sends a byte[] array (payload) as calldata to a specific address? If so, what is that function? Is it also raw_call()?
0 votes
1 answer
23 views

Function isn't returning the uint256 value after initializing mapping

I'm facing a problem with the function return type in solidity. Here is my code: // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; contract Birth { mapping(uint256 => bool) public ...
0 votes
1 answer
22 views

Modifier vs function call

What is more gas efficient and secure, using a modifier(for example only owner) or calling a function to verify state(calling a function that returns owner address and compares that to the address ...
0 votes
1 answer
33 views

Error When Passing Struct as Input to Function in Solidity

I'm trying to just call a function that has a struct argument...The thing is that Remix somehow doesn't recognize all the inputs from the struct in the function. I tried making the image very ...
  • 23
0 votes
1 answer
11 views

Function override error and abstract error after importing the contract

*this a contract for erc721: contract erc721{ event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); event Approval(address indexed _owner,address indexed _approved, ...
  • 19
1 vote
1 answer
14 views

Declaration error: undeclared identifier error in remix while using exiting Owner contract's function getOwner. Kindly help in solving

function withdraw() external isOwner() { address payable owner = address(uint160(getOwner()));//**this is the line I get err owner.transfer(address(this).balance); } owner contract: function ...
  • 19
4 votes
1 answer
28 views

Is it possible to use interface functions as types?

I would like to use a function defined in an interface as a function type, like this: pragma solidity >=0.8.17; interface Foo { function myFunction() external; } contract Contract { ...
1 vote
0 answers
45 views

Getting two different booleans calling a function 2 times in a row

I tried to create a function which could return me 2 different booleans after I call it two times in a row. I tried my best to use different random methods like storing block.timestamp in an uint, or ...
  • 21
1 vote
0 answers
31 views

How to identify where coin/token value is changed

I'd like to build an algorithm that analyzes value creation, transfer and destruction on a blockchain (such as new ETH minted, ETH gas burned, ERC-20 tokens transferred, etc.). Assuming I have a ...
1 vote
1 answer
89 views

Does it make any sense to specify reference type function input parameters as calldata if the given function is only called contract to contract?

As far as I am aware contract to contract calls store input arguments in memory. Or put more precisely they store them in memory and they can be accessed with CALLDATALOAD within the the new call ...
  • 141
1 vote
1 answer
15 views

What are the advantages/disatvantages to specify a struct param in a function as calldata vs. memory?

If I am not modifying the input parameter in the function body are there any reasons a reference type parameter should be labeled as stored in memory? More generally what are the reasons to go for ...
  • 141
0 votes
1 answer
12 views

Do i need to fund my contracts with eth

I have a protocol composed of multiple contracts which interact with each other, when a user call a transaction in one of the contracts, the contract calls other contracts functions . The question is :...
  • 187
0 votes
1 answer
35 views

contract recursive dependency

i have two contracts the first one has a function which must be called only by the second contract : contract A { address contractBAddress; uint256 number; modifier onlyB() { ...
  • 187
0 votes
1 answer
66 views

Why isn't calldata used in this function's argument? (OpenZeppelin/OwnableUpgradeable.sol)

Solidity noob here; reading about data locations i've learned that whenever you don't need to store or modify a function's input value it's actually more gas efficient to set its location to calldata (...
0 votes
1 answer
34 views

Error on "function getVersion public view returns (uint256)"

I get the error: "ParserError: Expected '(' but got 'public' --> contracts/FundMe.sol:10:25: | 10 | function getVersion public view returns (uint256) { | ^^^^^^ ...
0 votes
1 answer
39 views

How to write a request funds function in solidity

Hello everyone…I am trying to build a dapp where a user can request funds or ethers from a specific address and then that address can approve that function, then the person who requested the fund will ...
  • 3
0 votes
1 answer
30 views

Normal function asking to be made Payable

Below is the programme in solidity I wrote which assigns value to elements of an array. pragma solidity 0.8.16 ; contract arr { uint i = 0 ; people[] public person ; struct people ...
  • 33
0 votes
1 answer
17 views

how can i use mapping on structure inside another structure and create some elements

i want to create some Pledges for Startup there are these structures: struct Startup { address payable founder; string title; string startupDescription; uint goal; uint ...
  • 1
0 votes
2 answers
73 views

Where are Function stored in EVM?

I know that global variables are stored in slots of storage layout. But where are the functions stored? I would like to know technically why.
  • 189
0 votes
2 answers
152 views

modifier vs function which method is more efficient in terms of gas?

contract test { address public _onwer; error NotOwner(); modifier OnlyOwner1() { if(msg.sender != _onwer) { revert NotOwner(); } _; } function OnlyOwner2() ...
  • 189
1 vote
0 answers
18 views

Using interfaces as function parameters in solidity

Is it recommended to use contract interfaces as function parameters in solidity against using address. like... function doSomething (IERC20 token) external { ... } rather than function doSomething (...
1 vote
0 answers
59 views

Solidity function generic data type parameters

I have two structs: Struct A; and Struct B; I've two arrays: A[] a; and B[] b; And a function: getIndex() // ^^^*Generic: based on struct type passed* function getIndex(A/B memory [] ...
  • 111
2 votes
1 answer
60 views

Random function

Is this function safe? I want to generate a random number without any external input. abstract contract F { //current block time when the contract was created uint256 private currentTime=block....
0 votes
1 answer
23 views

Can't assign value to the 0 index of an array inside a function

So, I tried 3 simple codes on array // SPDX-License-Identifier: MIT pragma solidity 0.8.7; contract test{ uint[] public x; function testing() public { x[0] = 20; } } This throws ...
0 votes
2 answers
46 views

What happens if the actual return data type of a contract method is different from ABI

Suppose we want to handle ERC-20 tokens, but some of the token contracts does not comply with the standard completely. In IERC20 interface, transfer has the following signature. function transfer(...
  • 137
0 votes
1 answer
38 views

How can I write a `view/getter` function to see the results of another function

This is my code to remove an element from an array using "shifting method" : // SPDX-License-Identifier: MIT pragma solidity 0.8.7; contract Arrayelement{ //context : /* let an ...
0 votes
1 answer
31 views

How to automaticly burn erc-20 tokens after 1 month

Im working on a code to automaticly burn tokens after 1 month, is this even possible and if so how can i do this? Kind regards, Murk
  • 1
1 vote
0 answers
32 views

Ethereum contract "checksum" and contract simulating

I was looking at different contract simulators and I was wondering how are they made. I can see that they determine all of the functions that a given contract have, eg: --------------------------------...
  • 33
0 votes
1 answer
230 views

Web3.js contract call: Provider does not have a request or send method to use

Unfortunately, the very few similar questions either have outdated answers or solutions that did not work in my case. I'm getting the following error when calling a function in an Aave Smart Contract: ...
0 votes
0 answers
17 views

How to code event-dependent functions using web3 and solidity?

I'm a practitioner in solidity development, right now I'm testing some scripts in Remix, im wondering if its possible communicate events and functions using Web3 or other, to do something like event-...
0 votes
1 answer
125 views

I'm trying to call a function from a deployed contract, But I'm getting the following error:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted: ERC20: insufficient allowance { "...
0 votes
1 answer
129 views

revoking any or all smart contract permission given

my question is can I revoke any permissions given to a third party website to acces unlimitted funds from my account.if its possible can someone make a script or guide me into doing it.Cause my funds ...
0 votes
2 answers
25 views

Booolean Default Value

In a tutorial I have written the below code In this instance it would now throw a exception with the user feedback that the transaction did not go through. I don't know how the bool works in this ...
0 votes
2 answers
16 views

Assigning a New Owner

I am writing a contact that sets a new owner as per below but cannot understand why the function setNewOwner needs to be a view function. I would have thought assigning a new owner would change the ...
0 votes
2 answers
80 views

Can I import specific functions from other contracts and not the whole contract?

I am importing Access.sol by OpenZeppelin ("@openzeppelin/contracts/access/AccessControl.sol") in a contract. The main functions I am concerned with are setupRole(),hasRole() and grantRole()....
2 votes
2 answers
87 views

expected { but found constant

My code is: function equity_in_Hadcoins(address investor) external constant returns (uint) { return equity_Hadcoins[investor]; } // getting the equity in USD of an investor function equity_in_usd(...
  • 21
0 votes
0 answers
15 views

Can't run the getbook function in the below given code due to "Payable"error

''' pragma solidity >=0.1.0 <0.9.0; contract Day5 { constructor() payable { } struct Book { string title; string author; uint256 book_id; } Book[] types; uint count=1; function setBook(string ...
1 vote
1 answer
969 views

Can solidity function have optional parameter?

buyCoffee function has only 2 parameters. But if I call buyCoffee function with tip parameter in the test script, it does work. I tried to find some references in the ethers.js document but I couldn't....
0 votes
1 answer
28 views

Passing different parameter to function and modifer

I want to know that is there any way to provide different parametres to function and modifer while declaring them . Below is the code // SPDX-License-Identifier: MIT pragma solidity ^0.8.16 ; ...
  • 33
1 vote
1 answer
121 views

If the smart contract does not include the withdrawal function, will that ether be stored in the smart contract for life?

I am making a function to send ether to a smart contract and send the ether in the smart contract to another person. If the smart contract does not include the ability to send ether to other people, ...
  • 189
0 votes
1 answer
17 views

Displaying output with return parameter

Below is the simple code written by me // SPDX-License-Identifier: MIT pragma solidity ^0.8.16 ; contract blue { string first ; uint age ; function sett ( string memory fn , uint um) public ...
  • 33
0 votes
0 answers
38 views

Why function is not taking parameter

I have written following simple solidity code pragma solidity ^0.4.0; contract C1 { function f() { g(8) ; // simply passing an integer to another function } function g( uint x) returns (uint ) {...
  • 33
1 vote
1 answer
106 views

Private variables with public view functions

In the Openzeppelin ERC721.sol contract, there are private variables introduced: // Token name string private _name; // Token symbol string private _symbol; These variables are then assigned a ...
  • 123
1 vote
1 answer
98 views

Function cannot be declared as view because this expression (potentially) modifies the state

Compiling the contract returns this error. TypeError: Function cannot be declared as view because this expression (potentially) modifies the state. --> contracts/certification/token/...
  • 1,819
0 votes
1 answer
66 views

Basic For loop fails in Solidity

I created a simple For loop that should return an array of numbers. But it fails with errored: VM error: revert I guess there is something fundamental I am missing here, so I hope you guys can help ...
  • 1,819
0 votes
4 answers
161 views

Solidity : How to Use a function which is outside of a contract

//SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract funTesting { function add(uint x, uint y) public pure returns(uint) { uint sum; x = x+10; ...
0 votes
0 answers
23 views

Help with cycle function in Ethereum Blockchain

I am trying to understand the use of a particular function: cycle(uint256 vaultId, uint256[] _desiredIds, uint256 maxIterations, bool acceptAny) What is the purpose of this function? Why is called? I ...
0 votes
1 answer
29 views

Create contract with contract

I want to create a contract that can create contract itself I find something like this pragma solidity ^0.5.0; contract DaughterContract { string public name; uint public age; constructor( ...