Skip to content

Commit ee865a2

Browse files
docs: bytes wrapper example (#2714)
1 parent 8ce4905 commit ee865a2

File tree

1 file changed

+18
-1
lines changed
  • integration-tests/public/bytes

1 file changed

+18
-1
lines changed

integration-tests/public/bytes/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#![cfg_attr(not(feature = "std"), no_std, no_main)]
22

3+
/// Example for using bytes wrapper types (i.e. `ink::sol::FixedBytes<N>` and
4+
/// `ink::sol::DynBytes`) as message and event arguments.
5+
///
6+
/// # Note
7+
///
8+
/// In Solidity ABI encoding, `uint8[]` and `uint8[N]` are encoded differently from
9+
/// `bytes` and `bytesN`. In Rust/ink!, `Vec<u8>` and `[u8; N]` are mapped to Solidity's
10+
/// `uint8[]` and `uint8[N]` representations, so there's a need for dedicated Rust/ink!
11+
/// types (i.e. `ink::sol::DynBytes` and `ink::sol::FixedBytes<N>`) that map to Solidity's
12+
/// `bytes` and `bytesN` representations.
13+
///
14+
/// # References
15+
///
16+
/// - <https://use-ink.github.io/ink/ink_primitives/sol/struct.FixedBytes.html>
17+
/// - <https://use-ink.github.io/ink/ink_primitives/sol/struct.DynBytes.html>
18+
/// - <https://use.ink/docs/v6/background/solidity-metamask-compatibility#rustink-to-solidity-abi-type-mapping>
19+
320
#[ink::event]
421
pub struct FixedBytesPayload {
522
pub data: ink::sol::FixedBytes<8>,
@@ -21,7 +38,7 @@ pub mod bytes {
2138
pub struct Bytes;
2239

2340
impl Bytes {
24-
/// Creates a new bytes smart contract.
41+
/// Creates a new smart contract.
2542
#[ink(constructor)]
2643
#[allow(clippy::new_without_default)]
2744
pub fn new() -> Self {

0 commit comments

Comments
 (0)