Questions tagged [encoding]
The encoding tag has no usage guidance.
97
questions
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 ...
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.), ...
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 ...
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, ...
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 ...
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;
}
...
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 ...
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 ...
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 = ...
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 ...
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 &...
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 ...
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 ...
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(...
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 ...
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),
...
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) {
...
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 ...
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 });
}
}...
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(...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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 ...
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?
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:
...
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);
}
...
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:
...
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(&...
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"...
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.
...
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's Contract'.
I tried the UTF-8 \x27, and it also outputted '. I ...
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(...
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, ...
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) {
...
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.
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,
...
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 ...
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[] ...
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 ...
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 ...
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 ...
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 ...
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 ...
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?