Skip to main content

Questions tagged [encoding]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
13 views

Interpreting MPT branch node values

Consider a branch node for an MPT. Suppose the 17’th item in the branch node list is supposed to be NULL, because the branch node is not a “terminator” node. Ethereum documentation says NULL is ...
Joseph Johnston's user avatar
1 vote
1 answer
33 views

Redundant byte offset requirement in the Contract ABI Specification?

I've had the pleasure of finding out that, contrary to what I've been used to in the other byte-transferring/-interpretation systems (e.g. the C/C++ languages, the communication protocols, etc.), ...
Iaroslav's user avatar
  • 410
0 votes
1 answer
19 views

Small space appearing before string in remix

Hello I saw that type casting from bytes to string gave the same result whether the bytes are a string encoded or encodePacked. So I am trying some small contract in remix, to see how that works and ...
Aimane Harrak's user avatar
1 vote
1 answer
30 views

Why does EIP-155 add two extra zeros to the encoded transaction?

Quoting the EIP: [...] instead of hashing only six rlp encoded elements (nonce, gasprice, startgas, to, value, data), you SHOULD hash nine rlp encoded elements (nonce, gasprice, startgas, to, value, ...
Franco Victorio's user avatar
0 votes
1 answer
150 views

Using `types.DynamicFeeTx` for `EIP-1559` in golang creates an invalid raw transaction hex

I am trying to create a raw EIP-1559 transaction using the DynamicFeeTx method since I want to provide a gas tip cap. When I create this raw transaction, sign it and encode it using rlp, I get a raw ...
user131259's user avatar
2 votes
1 answer
287 views

Need help with abi decode and encode

the solidity data structure and code is as follows : struct Order { bytes32 sender; int128 priceX18; int128 amount; uint64 expiration; uint64 nonce; } ...
Invented Most's user avatar
0 votes
1 answer
131 views

ABI encode external function call with multiple arguments in Huff

I am trying to make an external function call, with multiple arguments, to a contract written in Solidity from a contract written in Huff. I am able to successfully call an external contract when the ...
JSON_Derulo's user avatar
2 votes
1 answer
132 views

Transaction data is not a multiple of 32 bytes

My understanding is that in a transaction's input data, the first 4 bytes, i.e. 8 characters, is reserved for a function signature. The rest of the data, after processed by the API, will be fitted to ...
Khanh's user avatar
  • 41
0 votes
1 answer
154 views

What is an alternative for ethers.AbiCoder in geth

I have a following code that encodes parameters with AbiCoder const name = "Crown"; const symbol = "Crown"; const decimals = 18; const coder = new AbiCoder(); const nameBytes = ...
Danijel Radakovic's user avatar
0 votes
1 answer
781 views

EIP712 TypedData Encoding With Nested Array of Structs Returning Wrong Signer

Grateful in advance for any help on this issue. I'm creating an EIP712 signature with TypedData that includes a nested array of structs, and it is returning the wrong signer when I do the encoding in ...
em_mutable's user avatar
0 votes
1 answer
474 views

How to encode arbitrary amount of parameters for encodeWithSignature without adding them to function definition?

Lets says we have Contract A that needs to call Contract B at a certain address which the requirements that Contract A doesn't know the exact parameter structure the function in that Contract B needs &...
CoderMan's user avatar
1 vote
1 answer
208 views

Use private key to encode your own public address

Let's say I use a wallet's private key to encode/digitally sign it's own public address, meaning that upon using its public address to decrypt that encoded/signed data, the result would be the public ...
user2340939's user avatar
0 votes
0 answers
60 views

Handling emojis as user input

I have a simple ERC721 from OpenZeppelin solidity smart contract that I modified so people can include a small message in their token that is stored as a string. When I mint from etherscan/polygonscan ...
otw's user avatar
  • 101
0 votes
1 answer
833 views

Encode Struct[] in ethers to pass to a dynamic bytes

I have a method in solidity: function getVotesWithParams( address account, uint256 blockNumber, bytes memory params ) public view virtual override returns (uint256) { return _getVotes(...
Ritzy Dev's user avatar
  • 303
1 vote
1 answer
127 views

How to merge calldata onchain

I'd like to append some data using some generic call in solidity. Lets say I have a function that looks like so: function doWork(uint256 number, string name) { //... } //Pseudo code the tuple is ...
Ritzy Dev's user avatar
  • 303
2 votes
2 answers
1k views

solidity decode packed data

uniswap creates paths in the following way: ISwapRouter.ExactOutputParams memory params = ISwapRouter.ExactOutputParams({ path: abi.encodePacked(WETH9, poolFee, USDC, poolFee, DAI), ...
Ritzy Dev's user avatar
  • 303
0 votes
2 answers
1k views

Uniswap Encode Path in typescript

I have a smart contract that is proxying a call to uniswap v3: function resolveImplementation(uint256 amountIn, SwapResolverOptions memory swapResolverOptions) public returns (uint256 amountOut) { ...
Ritzy Dev's user avatar
  • 303
2 votes
1 answer
1k views

How can I decode an array of structs that is encoded with arbitrary data?

I'm using calldata of abi.encode(123 , arrayOfStructs) and abi.decode(data[:32], (uint256)) to get 123. But I'm unable to get the array of structs with abi.decode(data[32:], (myStruct[])) On the other ...
Ryan Sea's user avatar
  • 658
6 votes
2 answers
4k views

How to call function with struct parameter in ethers?

My solidity: contract Test { struct Num { uint value; } function double(Num calldata num) external pure returns(Num memory) { return Num({ value: num.value * 2 }); } }...
António Gonçalves's user avatar
0 votes
2 answers
118 views

What happens if the actual return data type of a contract method is different from ABI

Suppose we want to handle ERC-20 tokens, but some of the token contracts does not comply with the standard completely. In IERC20 interface, transfer has the following signature. function transfer(...
ywat's user avatar
  • 217
0 votes
1 answer
279 views

abi encoding with selector and additional variable

I am trying to abi encode a function abc(address, string) the encoding looks like this Address.delegateCall(abi.encodeWithSignature("abc(address,string)", _address, _string)) but I actually ...
Adeeb Abdul Salam's user avatar
1 vote
1 answer
535 views

encodeWithSelector and call equivalence in vyper

What is the encodeWithSelector (from solidity) equivalent in vyper? For example, in solidity, if I wanted to directly the transfer function on our own contract using raw calls, I'd do: function ...
Patrick Collins's user avatar
7 votes
1 answer
1k views

Understanding Dynamic Types in calldata

Context I have recently been interested in how calldata is formed and interpreted. The Docs have a great section on how Dynamic Types are encoded into calldata. However, in practice I have trouble ...
Another0xDev's user avatar
0 votes
1 answer
2k views

ABI encode array of structs ethers.js

In Ethers.js, how do I encode an array of structs? The struct: struct FacetCut { address facetAddress; FacetCutAction action; //<--- enum bytes4[] functionSelectors; } Function's ...
dNyrM's user avatar
  • 938
0 votes
1 answer
682 views

How to encode string as bytes array?

A similar question has been asked but using web3 in java, however, I would like to encode a string to bytes[] in solidity itself.
MShakeG's user avatar
  • 1,825
0 votes
1 answer
761 views

How to format hex string to solidity address?

Say I have a hex string c4ef705a8a8f2db126b92013b4938230df2158b5 how can I format it as a solidity address using ethers js or another npm package to prepend 0x and correctly capitalise some of the ...
MShakeG's user avatar
  • 1,825
1 vote
1 answer
851 views

Why use abi encoding/decoding for method parameters? Why not simply separate the parameters in the method signature?

I have seen source codes where they would encode a bunch of parameters into a single bytes parameter and pass it into a function, what's the real purpose of doing it? For example: function hello(bytes ...
xenon's user avatar
  • 455
0 votes
1 answer
541 views

How do I parse a bytes32 in solidty?

I have a bytes32 object in memory or storage and I want to parse it into little chunks, for example into one uint8, followed by a bool, followed by uint10, followed by address. How can one do that? I ...
Marlo's user avatar
  • 361
0 votes
0 answers
1k views

How to decode string from bytes 32 in event log that is returned as hex on event log subscribe

I am using the web3.eth.subscribe method to listen for events on a contract. When an event occurs, I am using the web3.eth.abi.decodeLog to decode the data from the event. One of the parameters I am ...
penguindev11's user avatar
1 vote
1 answer
55 views

What is RLPn encoding?

I came across a code snippet where RLPn encoding is mentioned. What is this RLPn encoding and how is it different than RLP?
biplavo's user avatar
  • 934
1 vote
2 answers
2k views

EIP-1559: Why does geth expect an input list for types.txdata?

I manually composed, signed, and serialized the following raw transaction: ...
q9f's user avatar
  • 33k
0 votes
1 answer
438 views

Get list of all child contract addresses from contract factory in solidity

I have a factory contract with the below code: //SPDX-License-Identifier: no-license pragma solidity ^0.8.9; interface ChildInterface { function getStateVariable() external returns(uint); } ...
toddash's user avatar
  • 92
2 votes
1 answer
1k views

How to encode empty transaction fields?

I want to RLP-encode a(n unsigned) transaction. Some fields of the transaction can be empty/null/zero. I want to know how they are encoded, though. Let's assume the following transaction fields: ...
q9f's user avatar
  • 33k
2 votes
1 answer
2k views

How to web3 "encodeFunctionCall" a payable function?

I want to encode a call for mint() payable with a msg.value of 8 ETH. My code: web3.eth.abi.encodeFunctionCall({ type: 'function', name: 'mint', payable: true, value: web3.utils.toWei(&...
antoniopgs's user avatar
0 votes
1 answer
1k views

How to encode function signature besides parameters using eth_abi

I want to encode a contract's function signature together with parameters and values using python, more explicitely the eth_abi library. tokenA = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"...
newbie99's user avatar
  • 103
1 vote
1 answer
888 views

Web3.py: encoding zero-length byte array

I'm using Web3.py, and I'm trying to build a transaction to call a contract function where one of the arguments is of type "bytes". I want to call the function with a zero-length byte array. ...
galpo's user avatar
  • 145
1 vote
0 answers
181 views

What encoding standard for strings does Solidity use?

My contract name has an apostrophe, and when deployed it shows on Etherscan as John Doe's Contract instead of, 'John Doe&#39;s Contract'. I tried the UTF-8 \x27, and it also outputted &#39;. I ...
ThickMiddleManager's user avatar
3 votes
0 answers
1k views

abi.encodeWithSignature and abi.encode have inconsistent results with dynamic arrays

pragma solidity 0.8.0; function isMemberOfArrayEncodedTest(address member, address [] memory memberArray) public returns (string memory){ bytes4 sig = bytes4(keccak256("isMemberOfArray(...
John Sterlacci's user avatar
1 vote
1 answer
1k views

how to encode bool variables in solidity

i am trying to encode a bool variable as callback data (bytes). i am doing this by using abi.encodePacked for reduced space and cost and a custom decoding function. The issue is that after decoding, ...
Kaki Master Of Time's user avatar
2 votes
1 answer
485 views

Decoding signature for verification not working

I'm trying to verify a signature, but when I decode it, the function reverts. This is the function I'm using function source(bytes memory signature) public returns (bytes32 r, bytes32 s, uint8 v) { ...
SergioGaitan's user avatar
4 votes
3 answers
7k views

String to Hex in Ethers.js

Only one question: How can I convert string to hex in ethers.js I need some alternative to web3.utils.utf8ToHex() in ethers.
RafayelKh's user avatar
2 votes
0 answers
764 views

Encode nested structs using web3

I'm using Solidity 0.8.0 (so I'm using ABIEncoderV2) and web3.js 1.3.4 and I'm trying to call a contract's method passing a nested struct. erc1155.methods.safeBatchTransferFrom( owner, ...
Andrea Ciceri's user avatar
0 votes
1 answer
875 views

How to generate a signature with web3py like metamask does?

Most ethereum apps request signatures like this How exactly do i recreate this signature in web3 py? Is there any way i can view the data that gets sent thru metamask? I have tried the following code ...
DanielWhite's user avatar
1 vote
1 answer
2k views

How to encode arrays for solidity function calls

I want to understand how to encode the following arrays in Solidity. Dynamic Arrays For example, the following: function getDynamicUintArray() public pure returns (uint[] memory) { uint[] ...
rachid chami's user avatar
2 votes
0 answers
129 views

Is older web3.js UI code compatible with new contracts that use ABI coder v2?

The solidity 0.8.0 patch notes state: ABI coder v2 is activated by default. You can choose to use the old behaviour using pragma abicoder v1;. The pragma pragma experimental ABIEncoderV2; is still ...
Jesbus's user avatar
  • 10.5k
2 votes
1 answer
218 views

Solidity Call Encoded Return Value Difference

I've been working on decoding called return values. I've discovered that there's a difference between the encoding using the automatically created getter function of a public state variable and a ...
Fisticuffs's user avatar
3 votes
1 answer
4k views

Encoding address[] into bytes

I have an array of addresses (array[]) and I need to encode it into bytes and vice-versa. The reason for that is that I need to pass such an array to a function which only accepts bytes. I tried using ...
Wyctus's user avatar
  • 226
1 vote
1 answer
267 views

Why does this call to DSProxy fail?

Take these two contracts, both deployed on Kovan and with the source code verified: DSProxy: 0xa92Bed719071A4d33B0B348513E7e866a6ff6B3F TargetContract: 0xE3CD2e7a628b57d3e50c5f7B921182f676721bDF And ...
Paul Razvan Berg's user avatar
1 vote
1 answer
874 views

How is the signature generated when the function does not have parameters?

When the function has parameters, Solidity generates its signature by adding the parameter types after the function name, in between brackets, and taking a keccak256 hash of the resulting string. As ...
Paul Razvan Berg's user avatar
8 votes
2 answers
28k views

Convert String to Hex using ethers.js

If I use web3.js I can convert a string to hex with: web3.utils.toHex('4c7b7ffb66b344fbaa64995af81e355a') How do I use the same utility for ethers.js?
Patrick Collins's user avatar