New answers tagged

1

Each function has a signature. Inside of a transaction, there is a data field. This data field contains what function signature you would like to call along with what arguments - Vyper compiles to EVM bytecode. This bytecode contains the function signatures.


0

update @atomh33ls answer use abi.encodePacked pragma solidity ^0.6.0; contract E { uint256 public n; address public sender; function setN(uint256 _n) public { n = _n; sender = msg.sender; } } contract D{ uint256 public n; address public sender; function callSetN(address _e,uint256 _n) ...


1

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 obtain the address of the contract instance.


1

Your concept of "speed" is a bit wrong. Transactions which utilize less gas are not faster. Assuming that your transaction fits inside a block the only thing which affects the transaction speed is the gas price. The size of the transaction mostly does not affect the speed. Miners mostly order the transactions they take in their blocks by their gas ...


2

The return-value of a non-constant (neither pure nor view) function is available only when the function is called on-chain (i.e., from this contract or from another contract). When you call such function from the off-chain (e.g., from an ethers.js script), you need to execute it within a transaction, and the return-value is the hash of that transaction. This ...


2

A copy of structTest is saved separately in the array and in the mapping. In order to get rid of this redundancy, you can maintain an array of keys instead of values: uint[] all; // instead of `test[] all;` mappings (uint => test) map; function bla() { test memory structTest = test(5); all.push(10); // instead of `all.push(structTest);` map[...


2

CREATE2 is very cool, I was one of the engineers that worked on this project at Coinbase Commerce. You can read more about the implementation and our approach at the following blogpost https://blog.coinbase.com/usdc-payment-processing-in-coinbase-commerce-b1af1c82fb0


1

Is this how it's supposed to be? No, you can (and should) omit the uint amount parameter. Instead, the user should pass the desired amount within the msg.value. This way, the user (and not your contract) will be the one providing the funds.


1

Get the pool address Go to the Uniswap UI at https://app.uniswap.org/. Choose the token pair you want and then click the View pair analytics ↗. This will take you to a link like https://uniswap.info/pair/<poolAddress>. Note down poolAddress. Approve via Etherscan Go to https://etherscan.io/token/<tokenAddress>#writeContract where tokenAddress ...


1

The article is wrong. Value types like bool, uintXXX, bytesYY, etc. are stored in stack, for dynamic types you are forced to choose memory or storage. To read the array data just mload the address. Fixed size data arrays only contains the data, they don't store the length at the beginning like dynamic arrays. function test() public view returns (uint r) { ...


1

When a smart contract has been deployed its bytecode is saved on the chain. To execute the contract you send a transaction with the smart contracts address as recipient. Additional data can be passed to the contract as calldata which can be imagined as parameters to the contracts execution. When the node validates the transaction it notices that the ...


2

Due to their unpredictable size, dynamically-sized array types use a Keccak-256 hash computation to find the starting position of the array data. So in your example: The position of storageArr[0] is at keccak256(uint256(0)) + 0 The position of storageArr[1] is at keccak256(uint256(0)) + 1 The position of storageArr[2] is at keccak256(uint256(0)) + 2 Here ...


0

It has to do with addressing storage. Let's break it down. Consider a bool and an address. The bool takes 1 byte (limitation of optimization) and the address takes 20 bytes. So we need 21 bytes of storage. The EVM uses 32-byte words which are the smallest chunk of storage that is addressable. If you go contract A { mapping(uint => bool) b; mapping(...


2

This is about how the variables are packed together and about how smart the compiler is (hint: not very smart). The compiler only tries to pack subsequent variables together but it can't pack variables which have something else between them. In your first case the variables could all fit inside a single 32 byte slot, but if I'm not mistaken the compiler ...


1

You cannot transfer tokens from a contract address, unless that contract address has a function built-in to send a transaction or recover tokens in some way. It doesn't look like DAI has this built-in, so I'm afraid that your tokens are lost. In the future, double check the address you're sending to, and send a small test transaction if you're moving a ...


Top 50 recent answers are included