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

Add Bytes to the Primitive Data Types page #45

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sdk_version=""
sdk_repo=""
sdk_branch=""
rpc_url="https://sepolia-rollup.arbitrum.io/rpc"

# Parse command-line arguments
while getopts "v:r:" opt; do
Expand Down Expand Up @@ -90,7 +91,7 @@ process_directory() {
fi

# Run the cargo stylus check command
check_output=$(cargo stylus check 2>&1)
check_output=$(cargo stylus check -e $rpc_url 2>&1)

if [ $? -eq 0 ]; then
echo -e "Check passed in $folder_name"
Expand Down
28 changes: 24 additions & 4 deletions src/app/basic_examples/primitive_data_types/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ In this section, we'll focus on the following types:
- `U256`
- `I256`
- `Address`
- `bool`
- `Boolean`
- `Bytes`

More in-depth documentation about the available methods and types in the Alloy library can be found in their docs. It also helps to cross-reference with Solidity docs if you don't already have a solid understanding of those types.

## Learn More

- [Alloy docs (v0.3.2)](https://docs.rs/alloy-primitives/0.3.2/alloy_primitives/index.html)
- [`Address`](https://docs.rs/alloy-primitives/0.3.2/alloy_primitives/struct.Address.html)
- [`Signed`](https://docs.rs/alloy-primitives/0.3.2/alloy_primitives/struct.Signed.html)
- [Alloy docs (v0.7.6)](https://docs.rs/alloy-primitives/0.7.6/alloy_primitives/index.html)
- [`Address`](https://docs.rs/alloy-primitives/0.7.6/alloy_primitives/struct.Address.html)
- [`Signed`](https://docs.rs/alloy-primitives/0.7.6/alloy_primitives/struct.Signed.html)
- [`Uint`](https://docs.rs/ruint/1.10.1/ruint/struct.Uint.html)
- [Stylus Rust SDK](https://docs.rs/stylus-sdk/latest/stylus_sdk/index.html)
- [`Bytes`](https://docs.rs/stylus-sdk/latest/stylus_sdk/abi/struct.Bytes.html)
- [Solidity docs (v0.8.19)](https://docs.soliditylang.org/en/v0.8.19/types.html)

## Integers
Expand Down Expand Up @@ -127,6 +130,23 @@ let response = match frightened {
console!("{response}");
```

## Bytes

The Stylus SDK provides this wrapper type around `Vec<u8>` to represent a `bytes` value in Solidity.

```rust
let vec = vec![108, 27, 56, 87];
let b = Bytes::from(vec);
// Out: Stylus says: '0x6c1b3857'
console!(String::from_utf8_lossy(b.as_slice()));

let b = Bytes::from(b"Hello!".to_vec());
// Out: Stylus says: 'Hello!'
console!(String::from_utf8_lossy(b.as_slice()));
```

Note: Return the `Bytes` type on your Rust function if you want to return the ABI `bytes memory` type.

## Boilerplate

### src/lib.rs
Expand Down
Loading