Questions tagged [encoding]
The encoding tag has no usage guidance.
94
questions
0
votes
1
answer
69
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
46
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
0
answers
13
views
Signing a message which includes another signature
I'm trying to implement a commit-reveal scheme, where I also want to sign the input parameters to the Solidity function which commits the encrypted message. The signature verification of the input ...
0
votes
1
answer
59
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
0
answers
295
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
154
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
69
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
38
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
0
answers
118
views
How to use keccak256 in assembly instead of keccack256(abi.encodePacked(address))?
I'm trying to use assembly to compare the gas usage of two implementations of the same function.
The following works correctly:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import ...
0
votes
1
answer
476
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
86
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
816
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
1
answer
749
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) {
...
0
votes
0
answers
38
views
Error while running slither
Getting this error :
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 11: invalid start byte
while running slither . on the root of my brownie project .
have someone faced this ...
0
votes
1
answer
717
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
3k
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
75
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
192
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
490
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
573
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
623
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
813
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
413
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
50
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
399
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
757
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
166
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
998
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
419
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
6k
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
739
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
803
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
194
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
3k
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
258
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
799
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
23k
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?
3
votes
1
answer
1k
views
json rpc hex string weird padding/encoding
When sending eth_call to get erc20 token WETH name and symbol I get hex response padded with bunch of zeros and a mysterious digit '2'.
for symbol I get response:
"...
1
vote
1
answer
293
views
Where does the length parameter end and the actual string start in an abi encoded string?
Assuming I decided to ABI encode a very long string (for the purpose of this question I just picked an arbitrary 5-paragraph lorem ipsum text generate by https://www.lipsum.com/feed/html) and get out ...
1
vote
1
answer
198
views
Error: Invalid bytes6 value
I'm trying to create a TicketPurchaser application. Here is the whole code for the smart contract, although I think the problem I'm asking about is a type error, most of the code is not important.
...