18 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 ...
user avatar
11 votes
Accepted

does using external over public in a library reduce any gas costs?

Declaring a function as external rather than public does not affect gas usage at all, neither in contracts nor in libraries. In earlier versions of Solidity, only external functions could take ...
user avatar
  • 1,526
7 votes

I see no way to obtain the return value of a non-view function (ethers.js)

Here is an example using Events: const tx = await contract.transfer(...args); // 100ms const rc = await tx.wait(); // 0ms, as tx is already confirmed const event = rc.events.find(event => event....
user avatar
  • 126
7 votes
Accepted

How to bubble up a custom error when using DELEGATECALL?

Check out this function I modified from the openzepplin's Address.sol. function _delegatecall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory ...
user avatar
  • 186
5 votes

Can you test a contract function transaction by calling it instead

Your theory is correct. MetaMask sends a static (local) call to the contract. The call is the same as a real transaction, except 1) its state changes are not persisted 2) it doesn't cost any gas, ...
user avatar
4 votes

How to get ETH contract balance with Ethers.js

In the context of testing a contract with Hard Hat: const { ethers, waffle} = require("hardhat"); const provider = waffle.provider; const balanceInWei = await provider.getBalance(contract....
user avatar
  • 141
4 votes

How to configure `truffle test` to fork the main/rinkeby chain as its local chain?

You can fork Rinkeby or the Mainnet pretty easily using Ganache-CLI. Read this article for a detailed explanation https://blockheroes.dev/test-smart-contracts-on-mainnet/ The simplest command is: ...
user avatar
4 votes

what is expansion cost?

The formula in your question describes a gas cost for the total amount of memory allocated in a contract call (i.e. the biggest memory location that contains a nonzero value. Zeroing memory after ...
user avatar
4 votes

Call contract and send value from Solidity

A more modern style, as the last answer has gone a bit out of date: (tokenInAfterFee, tokenOutAmt) = spclContract.swap{value: msg.value}(_spctToSwap); (edit: the accepted answer was edited after I ...
user avatar
3 votes
Accepted

ethers - call an overloaded function with a specific signer

This took a fair amount of playing around, but finally discovered that: await NFT.connect(sender)['safeTransferFrom(address,address,uint256)']( sender.address, recipient.address, ethers....
user avatar
3 votes

What is calldata?

The Calldata is a read-only byte-addressable space where the data parameter of a transaction or call is held. Unlike the Stack, to use this data you have to specify an exact byte offset and number of ...
user avatar
  • 536
3 votes
Accepted

Why are all ethersjs & web3js calls to BSC network failing?

Try changing provider. I use Chainstack and it works great. Follow these steps to sign up on Chainstack, deploy a node, and find your endpoint credentials: Sign up with Chainstack. Deploy a node. ...
user avatar
  • 376
2 votes

Does it cost gas when sending ether from a contract to an address?

Think of it like this, Who call the function/initialize a transaction will pay for the gas fee A smartcontract's function can not just run by itself, either another smartcontract or an EOA must call ...
user avatar
2 votes

What is the execution order of Inherited constructors in solidity?

Current Solidity docs provide the answer in this paragraph: https://docs.soliditylang.org/en/v0.8.13/contracts.html#multiple-inheritance-and-linearization Basically: Solidity guarantees that all the ...
user avatar
2 votes

How to get value of a contract public property using web3.eth

None of the other answers work for me. This does: import Web3 from "web3"; const address = "0xe9e7..."; const abi = "[{..."; const web3 = new Web3(); // pass your ...
user avatar
  • 121
2 votes

How to remove/increase execution timeout of the geth's evm?

You can run geth with the --rpc.evmtimeout flag to change the 5s timeout. If you set it to 0 , then timeout will be infinite. Check geth --help for more info.
user avatar
2 votes
Accepted

Having trouble figuring out EIP-1599 params for contract transaction in ethers.js

The values maxPriorityFeePerGas, maxFeePerGas and value should be in Wei (the smallest unit on Ethereum). You can use Ethers.js' parseUnits to convert a value in Gwei or Ether to Wei: contract....
user avatar
  • 5,139
2 votes

The longer a smart contract interaction's code is, the higher the gas?

The minimum gas value for a transaction is 21000 (e.g. simple Ethereum transfer). Any additional (such as calculations / read /store /... operation) will incur additional costs. These operations ...
user avatar
  • 514
2 votes
Accepted

Getting the functions of an unpublished contract

To view the code: On the Contract tab of a given contract on BscScan, there is a button that says "Decompile ByteCode". Click that and you'll be taken to a new page called "EVM bytecode ...
user avatar
2 votes
Accepted

Web3.js. How to get returned value when the transaction takes minutes to be mined

You have to listen to the contract events. "mint" function is done by the standards that should emit the Mint event. And then you can do something like this: contract.events.allEvents() .on('...
user avatar
2 votes
Accepted

User Whitelisting on Smart Contract

Previous user's answer isn't really workable with a possible user list in the millions--you'd be spending billions of gas to add all the users, which is obviously too much. What you want is a Merkle ...
user avatar
  • 316
1 vote

How to tell whether a 0x address is a wallet or a contract?

There is no way to tell just by looking at the string. You would need to look into the code to see the difference.
user avatar
1 vote
Accepted

What is SwapRouter in Uniswap v3?

The swapRouter is the contract doing, quoting Uniswap comments, "important verification" (in terms of amounts, slippage, etc) and, novelty of Uniswap V3, handling the swap callback which is ...
user avatar
1 vote

How to interact with Ethernaut contracts via Remix

The Ethernaut challenges take place on the Rinkeby test network. Are there multiple ways to interact with an already deployed contract? Yes, you can basically interact with the contract from the ...
user avatar
  • 5,919
1 vote

How can I decode calls to the songbird network?

Just adding to the previous answer to help people understand how to interpret the encoding. The call data is composed of 2 parts : Function selector (4 first bytes) Parameters (everything after the 4 ...
user avatar
  • 5,919
1 vote

How can I decode calls to the songbird network?

To decode calls on Songbird network you can use this tool: https://decoder.aflabs.si/. It uses the songbird explorer to get contract ABI from the contract's address and then decodes the function call ...
user avatar
1 vote

Decode input parameter without ABI

Solidity is a typed language, so it's aware of the types of function parameters. When you call a certain function on a contract, Solidity knows that the type of the first parameter is an address, and ...
user avatar
  • 5,139
1 vote
Accepted

Can I use delegatecall with the target contract's storage?

If you want contract A to call a function of contract B and use the storage of contract B, that's simply calling a function on contract B. There is nothing fancy about it, as this is the basis of ...
user avatar
1 vote

How does msg.data is encoded?

The data get's encoded with the abi encoder. function withManyArguments( flashToken, flashAmount, balanceBefore, arbToken, zrxData, oneSplitMinReturn, oneSplitDistribution, flag ) { bytes ...
user avatar
1 vote

How to bubble up a custom error when using DELEGATECALL?

Normally a call or a delegatecall doesn't revert while calling a function that reverts. (bool success, bytes memory result) = to.call/delegatecall{value,gas,etc}(data). The success variable will ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible