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

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(...


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) ...


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 ...


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 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

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

Option #1 - compile your code directly with solc executable, for example: solc --bin --abi --optimize --optimize-runs=200 --output-dir=artifacts MyContract.sol Option #2 - extract the artifacts from the output of truffle or solc.js: const fs = require("fs"); const INPUT_DIR = "YourJsonFilesDirectory"; const OUTPUT_DIR = "YourArtifactsDirectory"; for (...


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; ...


2

For on-chain transactions, you can use abi.encodeWithSelector. This article has a ton of great information about it. In your case, you can do the following: bytes4 methodSig = 0xbeabacc8; address addressOne = address(0); address addressTwo = address(1); uint256 uintOne = 2; abi.encodeWithSelector( methodSig, addressOne, addressTwo, ...


2

You can execute the call the following way (members of addresses, abi.encode*, low-level calls): Example 1: Call using already calculated function signature (this answers your question) bytes memory transferPayload = abi.encodeWithSelector(bytes4(0xbeabacc8), param1, param2, param3); bytes memory executePayload = abi.encodeWithSignature("execute(address,...


1

Strictly speaking, there are no tuples in your example. Type uint8[] is a dynamic array type, not a tuple. Here is the encoding decomposed: 47958782 // Function selector (4 bytes) 0000000000000000000000000000000000000000000000000000000000000040 // Offset of the first argument (32 bytes) ...


1

Web3 provides a Contract.encodeABI class method: https://web3py.readthedocs.io/en/stable/contracts.html#web3.contract.Contract.encodeABI.


1

For Gnosis MultiSigWallet, I use the following: function submitTransaction(options, msWalletAddr, contractAddr, contractAbi, functionName, functionArgs, privateKey) { return sign(options, msWalletAddr, "submitTransaction", [contractAddr, "0", encode(contractAbi, functionName, functionArgs)], privateKey); } function confirmTransaction(options, ...


1

You need to have ABI files for the smart contract. Then you can use Node.js console, JavaScript or TypeScript to generate a payload for Data to trigger a smart contract function call with the transaction. Steps to make such a call Get ABI files needed for the smart contracts, usually from Github Create a snippet that is pasted in Node.js console for the ...


1

You could get rid of it in the function-call as well, i.e.: (uint128 stakeId, address behalf) = abi.decode(userData, (uint128, address)); But I suppose that would just beat your purpose to begin with. So the quickest workaround which comes to mind is to just add a dummy reference: (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, ...


1

What are you doing here is fetching the 'bytecode' only from the JSON map. output.contracts["test.sol"][contractName].evm.bytecode.object The code snippet above is going in: contracts -> .sol file -> file_name object -> evm -> bytecode if you look closely in this console.log: console.log(output.contracts["test.sol"]["test"]); you will notice that it ...


1

If you are using web3, you can encode it with: web3.eth.abi.encodeParamter('string', <lorem_ipsum_text>) You can then decode the output with the following: web3.eth.abi.decodeParamter('string', <lorem_ipsum_encoded_string>) Encoding is based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to ...


1

From the details that you've posted, I believe that the address parameter in your event is indexed. Therefore, it is not going to be provided in the data string, but in the topics array at the 2nd entry (i.e., topics[1]). If you want the actual address, then you can do: const address = "0x" + topics[1].slice(26); // get rid of 24 leading zeros Since the ...


1

Is there any difference if I compile everytime I want to deploy another multisig wallet. No, provided you haven't changed anything in the contract. In case if you haven't changed anything in the contract and try compiling it again, truffle returns the below result > truffle compile Compiling your contracts... =========================== > Everything ...


1

Basically, a tuple is encoded as if all its members were separate parameters, so the following function returns true: struct Foo { uint x; uint y; uint z; } function foo () public pure returns (bool) { return keccak256 (abi.encode (1, 2, 3)) == keccak256 (abi.encode (Foo (1, 2, 3))); }


1

Once your contract is deployed, you can use assembly code within solidity to access your byte code as seen in this example below. The benefit of this vs just saving a parameter is that you are confident this is actually the byte code of the contract. One downside is that trying to use this in the constructor I do not believe will work. assembly link ...


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

Truffle Flattener Yes, there is truffle-flattener (https://github.com/nomiclabs/truffle-flattener/) that combines all your smart contracts files into one. And it works well with Truffle. Here is how to use it: 1) Install globally: npm install -g truffle-flattener 2) Use it, for example, to flatten your smart contract 'SimpleToken.sol' like this: truffle-...


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


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