242
votes
Accepted
What is the difference between a transaction and a call?
Call
A call is a local invocation of a contract function that does not broadcast or publish anything on the blockchain.
It is a read-only operation and will not consume any Ether. It simulates what ...
eth♦
- 83.3k
131
votes
Accepted
Difference between CALL, CALLCODE and DELEGATECALL
DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the sending contract which needs to trust ...
eth♦
- 83.3k
70
votes
Accepted
How to call a contract method using the eth_call JSON-RPC API
Summary
Your original contract code would not work correctly until I added a constant to the function definition to indicate that this function does not modify the blockchain.
I had to use the method ...
58
votes
Accepted
How can you call a payable function in another contract with arguments and send funds?
Update per @Girish comment, in Solidity 0.6+ the syntax has changed to:
address.function{value:msg.value}(arg1, arg2, arg3)
Original
The general syntax for calling a function in another contract ...
eth♦
- 83.3k
50
votes
What is the difference between a transaction and a call?
The difference between in a call and a transaction is the following:
transactions are created by your client, signed and broadcasted to the network. They will eventually alter the state of the ...
50
votes
Accepted
I see no way to obtain the return value of a non-view function (ethers.js)
The return value of a non-pure non-view function is available only when the function is called and validated on-chain.
When you call such function off-chain (e.g. from an ethers.js script), you need ...
47
votes
How to get return values when a non view function is called?
It is not currently possible to return values from functions which modify the blockchain. To receive a return value, you can mark functions as "pure" or "view".
For state-changing functions, the only ...
41
votes
Accepted
What is calldata?
Here is an example from What is an ABI and why is it needed to interact with contracts?
contract Foo {
function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; }
}
If we wanted to call ...
eth♦
- 83.3k
39
votes
Can contracts pay the gas instead of the message sender?
At present the user initiating the transaction must pay the fee. However Serenity is likely to enable 'contract pays' schemes. (See Vitalik's blog post here) A possible work around is a contract which ...
34
votes
'internal' keyword in a function definition in Solidity
Yes. The internal modifer means that the function can only be called within the contract itself and any derived contracts.
private functions are not available in derived contracts.
From the docs:
...
31
votes
How can I return multiple strings from a contract function?
There are a few types of string values that you may be referring to.
bytes1 - bytes32: fixed size.
bytes or string: dynamically sized.
Solidity supports functions with multiple return values.
...
30
votes
How to get ETH contract balance with Ethers.js
getBalance is a function of the Ether.js blockchain provider object, it is used this way :
const balance = await provider.getBalance("address");
Note that you can use contract.address to ...
29
votes
Can contracts pay the gas instead of the message sender?
No, a sender with zero ether cannot "ask" a contract to pay for the gas costs. A sender with zero ether cannot even send a transaction.
More details: The sender of a transaction must have enough gas ...
eth♦
- 83.3k
27
votes
Accepted
How does the delegatecall method work to call to another contract's method?
Here is a snippet of D using delegatecall on E from Difference between CALL, CALLCODE and DELEGATECALL
contract D {
uint public n;
address public sender;
function delegatecallSetN(address _e, ...
eth♦
- 83.3k
27
votes
Calling function from deployed contract
Use an abstract contract (preferred)
Further clarifications to @Edmund's answer:
contract A { // This doesn't have to match the real contract name. Call it what you like.
function f1(bool arg1, ...
eth♦
- 83.3k
26
votes
Accepted
'internal' keyword in a function definition in Solidity
The internal modifier can be better compared with protected in object-oriented programming languages. Internal functions of the contract C are visible to the code running at the current address (i.e. ...
26
votes
I see no way to obtain the return value of a non-view function (ethers.js)
While the return value of a function call executed on-chain cannot be returned off-chain, you can however simulate a function call on-chain to see what that function call would return.
In ethers, you ...
25
votes
Accepted
Call contract and send value from Solidity
Here's an approach that's simpler and checked by the compiler:
contract contractA {
function blah(int x, int y) payable {}
}
contract contractB {
function invokeContractA() {
...
25
votes
Accepted
How can you share a struct definition between contracts in separate files?
You can with a library! Here's an example:
pragma solidity ^0.4.17;
library SharedStructs {
struct Thing {
address[] people;
}
}
contract A {
SharedStructs.Thing thing;
}
...
24
votes
Accepted
What are *C*, *E* and *S* properties in message call return object?
result is a BigNumber object that is stringified to something like { [String: '5'] s: 1, e: 0, c: [ 5 ] }. You can use BigNumber methods, like result.toNumber() to see it better.
When integers are ...
eth♦
- 83.3k
24
votes
Accepted
How to load contract from address- remix?
This process works as follows:
You must compile the same exact code that the contract you are trying to load.
Once the compile succeeds, you have to be on the same network that the contract is, by ...
23
votes
Accepted
How do I know how much gas to use when calling a contract?
There are estimateGas APIs in both the JSON-RPC
and Javascript.
They are estimates and for developers that want further precision, testing is required, possibly on a private chain.
If too much gas ...
eth♦
- 83.3k
22
votes
Accepted
get array.length without a getter from other contract?
No. You need to present a function that will return the array length as a uint.
Something like
function getCount() public view returns(uint count) {
return array.length;
}
It's a pretty common ...
21
votes
Accepted
Does every node execute the contract code for each transaction?
Yes, the answer is quite logic. Every node has to verify the results of a transaction which invokes a smart contract. The result is that at least every full node will execute the code.
The hash of ...
19
votes
Accepted
What is the order and concurrency behavior of multiple calls to a contract in a single transaction?
Transactions are executed purely sequentially, in an order set arbitrarily by the miner who wins each block. Higher gas priced transactions are more likely to make it into a block, so that contributes ...
18
votes
Accepted
What happens when two smart contracts recursively call each other?
They will run out of gas.
Each smart contract can only be invoked by a transaction. Transactions costs fees and executing contracts costs gas, which are a kind of additional fees for each executional ...
18
votes
Accepted
Call function on another contract
You can do:
/* MORTAL CONTRACT HERE */
contract Name is mortal{
mapping(address=>string) public text;
string public test;
function register(string _text){
text[msg.sender] ...
18
votes
Accepted
What happens when a smart contract gets several similar calls in the same block?
What happens if Bob, Alice and Eve all call the Greeter at the same time and all three calls are in the same block?
The three transactions would get called, not necessarily in sequence, and the last ...
18
votes
Accepted
How does one contract send ether to another contract with more than 2300 gas?
In order to send Ether to another contract while specifying the amount of gas, use the call function.
targetAddress.call.gas(200000).value(this.balance)(); will call the fallback function.
...
18
votes
Accepted
Pass a function as a parameter in Solidity
Functions (aka Methods) are specified by the ABI, and have a Method ID, which is the first 4 bytes of the sha3 (Keccak-256) of the method's signature.
Here's an example of invoking someFunction on ...
eth♦
- 83.3k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
contract-invocation × 1171contract-development × 363
solidity × 354
web3js × 187
contract-design × 184
transactions × 120
contract-deployment × 116
go-ethereum × 93
contract-debugging × 65
remix × 55
gas × 52
truffle × 42
tokens × 38
evm × 35
abi × 35
metamask × 33
javascript × 33
ethers.js × 31
blockchain × 30
addresses × 30
events × 29
erc-20 × 28
nodejs × 28
ether × 27
etherscan × 21