Hot answers tagged

5

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 baz with the parameters 69 and true, we would pass 68 bytes in total, which can be broken down into: 0xcdcd77c0: the Method ID. This is derived as the ...


4

Unfortunately, you cannot store the deploying contract's bytecode as a variable in the contract directly, as that creates a circular reference. From the docs: This property can not be accessed in the contract itself or any derived contract. It causes the bytecode to be included in the bytecode of the call site and thus circular references like that are ...


4

With Brownie Brownie allows you to generate calldata using the ContractTx.encode_input method: >>> token <Token Contract object '0x79447c97b6543F6eFBC91613C655977806CB18b0'> >>> token.transfer.encode_input(accounts[0], 1000) ...


3

As of version 4.x, the answer is yes, the contract ABI must be provided. Creating a contract with no ABI and no provider or signer: let tokenContract = new ethers.Contract(tokenAddress); Yields this error: TypeError: Cannot read property 'forEach' of undefined Creating a contract with just no provider or signer: let tokenContract = new ethers.Contract(...


3

You can use ERC930 Eterenal Storage pattern in contract design, through which you can be use to write up-gradable contract by separating your contract's storage and business logic. I can came something what are you expecting to do (correct me if i'm wrong) in RocketPool's smart contract .


2

you can use web3 built-in functionality: web3.eth.abi.decodeParameters(typesArray, hexString); see link


2

Is that correct? If yes, why do we do this and where can I find some further documentation? Yes, you are correct. Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in a dynamic parameter (bytes) as opposed to a static one ...


2

I've found a straight forward way to solve it by extending the contract B ABI with the events of contract A. A is inside of B, so B can call to A methods and trigger A events. While A's methods are encapsulated, A's events are not. By this line of thinking in makes sense to include A's events in B. This can be done manually by a copy-paste or with code: ...


2

You can use the Ethers.js utils to pack the data how the v2 AbiEncoder would: https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=packed#solidity Example from the docs: let result = utils.solidityKeccak256([ 'int8', 'bytes1', 'string' ], [ -1, '0x42', 'hello' ]); console.log(result); // '...


2

You might get more specific, on-point ideas if you describe what you DO want to do. web3 is merely an abstraction of lower-level methods, so yes, such methods exist. Other abstractions exist as well: other JS libraries libraries in other languages JSON RPC which is accessible via curl and tools like Postman Etherscan and MyEtherWallet provide a UI Mist ...


2

There is no real problem with your code. Just take a look at the error message. It tells you that you only have 2 seconds time to execute your code. Cause of the nature of blockchain (and ethereum) your deploy will most likely take longer than this. So how do you fix it? In you project root folder you have a file called package.json. When running tests you ...


2

You got the function selector right (0x2f0c92d3), but you failed to correctly ABI encode the address parameter. It should be left-padded with zeros so that it's 32 bytes wide. Try this instead: 0x2f0c92d3000000000000000000000000dc1f5d644e4016f3da89fe002f63fbeb8e071cf1


2

Maybe you can use the online Ethereum IDE (Remix): Paste the whole code of the address you posted. Select the same compiler version: v0.4.25+commit.59dbf8f1. Select the contract by name: SaiProxyCreateAndExecute. Press on Compilation Details and check the functionHashes section. You will get something like the following: { "581f3c50": "createAndOpen(...


2

For every function, you want to calculate keccak256(signature) (try https://emn178.github.io/online-tools/keccak_256.html) signature is a concatenation of function's name and parameters' types in parentheses, omitting all spaces and parameter names. For example function transfer(address to, uint256 amount) has signature transfer(address,uint256) ...


2

With web3.js v1.2.x, you can use function web3.eth.abi.encodeFunctionSignature: const selector = web3.eth.abi.encodeFunctionSignature({ type: "function", name: yourObj.funcName, inputs: yourObj.params.map(param => ({type: param})) }); Or simply: const selector = web3.eth.abi.encodeFunctionSignature("getSupplyRate(address,uint256,uint256)"); ...


2

A function selector allows you to perform dynamic invocation of a function, based on the name of the function and the type of each one of the input arguments. For example, suppose you have: contract Contract1 { function func(uint256 x, uint8 y) public returns (uint32, uint32) {...} } contract Contract2 { Contract1 public contract1 = new Contract1()...


2

You could store them in variables. Doing so would provide no assurance of fidelity with the actual contract as would rely on the deployment ceremony doing it honestly. Another issue is you would have to convert the ABI to Hex or find another way to escape the quotes. pragma solidity 0.5.16; contract SimpleIntrospection { bytes public BYTECODE; ...


1

In general, you cannot just concatenate partial ABI encodings, as ABI encoding splits variable length parameters into fixed and variable parts. For function Foo the correct encoding would be: selector (4 bytes) name offset (32 bytes) symbol offset (32 bytes) decimals (32 bytes) totalSupply (32 bytes) address (32 bytes) value (32 bytes) name length (32 ...


1

You can decode it programmatically with web3.js (tested with version 1.2.1): const Web3 = require("web3"); const web3 = new Web3("https://mainnet.infura.io"); const addr = "0x241e82c79452f51fbfc89fac6d912e021db1a3b7"; const abi = [{"constant":false,"inputs":[{"name":"delegate","type":"address"}],"name":"approveDelegate","outputs":[],"payable":false,"...


1

Add a filter to the call with fromblock > 0: contract.getPastEvents("allEvents", { fromBlock: 1}).then(console.log);


1

Actually the data of deployed contract transaction is bytecode concatenate with abi encoded of constructor parameters. Here is example: Token.sol pragma solidity 0.5.1; contract Token { uint256 public totalSuply; constructor (uint256 _totalSuply) public { totalSuply = _totalSuply; } } The bytecode of Token.sol: ...


1

For your question no. 1: Search for "type": "constructor" in your ABI. From this object, you can see the inputs that has an array of parameters along with their name and type. Example: { "inputs": [ { "internalType": "uint256", "name": "_ff", "type": "uint256" }, { "internalType": "string", "...


1

name, symbol, and decimals are marked as OPTIONAL within the ERC20 Token Standard. Each of the examples you have referenced do not include them (or includes them differently from how they are specified in your abi). The High Performance Blockchain contract specifies the number of decimals as DECIMALS in all caps, rather than the expected decimals The Icon ...


1

The ABI can be converted to a Solidity interface which contains all of the function names: In Python - abi2solc In Javascript - abi2solidity


1

From the Solidity documentation: If the event is declared as anonymous the topics[0] is not generated Unlike regular events, anonymous events do not contain an indexed keccak of their signature. Because of this they cannot be easily searched for, or decoded with certainty unless you have the specific contract ABI. To make an event anonymous, include the ...


1

In both your code examples, a function selector is used to tell the target contract what function you're calling. In the second case, Solidity is generating the code that uses the function selector for you. This is generally a better approach. (No need for you to deal with function selectors directly if the compiler can do it for you.) That said, you do ...


1

I think I would focus on the testing methodology. The contract looks okay to me. I fiddled with it a little to test the original two functions and ended up with something that seems to work. It works for both examples, e.g. 255, "test". I didn't find a case where it doesn't work. Admittedly, did not test very much. pragma solidity ^0.5.0; contract ...


1

If I'm not mistaken, the issue is token.transfer.selector is trying to work out the signature from the source code. It would be equivalent to abi.encodeWithSelector(bytes4(keccak256(bytes(signature))); https://solidity.readthedocs.io/en/v0.5.2/units-and-global-variables.html?highlight=selector#abi-encoding-and-decoding-functions Differentiation is not ...


1

Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in two parameters: a dynamic array of addresses (_receivers) and a static uint256 (_value). When encoding the parameters, the EVM looks to see if the parameters are static ...


1

I solved it by downgrading to web3.1.0.0-beta.37. This is the latest release I could find which doesn't have this problem.


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