Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] alloy_primitives::U8 doesn't have the 'abi_encode' method #854

Open
benli5510 opened this issue Jan 14, 2025 · 1 comment
Open

[Bug] alloy_primitives::U8 doesn't have the 'abi_encode' method #854

benli5510 opened this issue Jan 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@benli5510
Copy link

benli5510 commented Jan 14, 2025

Component

sol-types

What version of Alloy are you on?

lastest version, 0.8.18

Operating System

Linux

Describe the bug

use alloy_primitives::{U256, U8};
use alloy_sol_types::SolValue;

fn main() {
    let data = U256::from(0);
    let encoded: Vec<u8> = data.abi_encode();

    let data2 = U8::from(0);
    let encoded: Vec<u8> = data2.abi_encode();
    // let encoded: Vec<u8> = alloy_primitives::Uint::<8, 1>::abi_encode(&data2);
}

It will give the error: no method named abi_encodefound for structalloy_primitives::Uint in the current scope for the U8 data.
The above U256 has no errors.

@benli5510 benli5510 added the bug Something isn't working label Jan 14, 2025
@DaniPopes
Copy link
Member

This is a known limitation: we specialize SolValue for Vec<u8> to encode like bytes, and for Vec<T> to encode like T[].

// TODO: `u8` is specialized to encode as `bytes` or `bytesN`
// [] u8 => sol_data::Uint::<8> [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants