From a6903b0b282496cc9b45c46862f32e3a366c656e Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 11 Apr 2025 18:08:28 +0530 Subject: [PATCH 1/5] feat(`landing`): examples tab group --- vocs/docs/components/Tab.tsx | 2 - vocs/docs/pages/index.mdx | 143 ++++++++++++++++++++++++++++++++++- 2 files changed, 142 insertions(+), 3 deletions(-) diff --git a/vocs/docs/components/Tab.tsx b/vocs/docs/components/Tab.tsx index e3a4a08..d688246 100644 --- a/vocs/docs/components/Tab.tsx +++ b/vocs/docs/components/Tab.tsx @@ -1,5 +1,3 @@ -import * as React from 'react' - export default function Tab() { return (
diff --git a/vocs/docs/pages/index.mdx b/vocs/docs/pages/index.mdx index 9659405..2d6d731 100644 --- a/vocs/docs/pages/index.mdx +++ b/vocs/docs/pages/index.mdx @@ -18,5 +18,146 @@ import Tab from "../components/Tab"; GitHub - + +:::code-group + +```rust [read_contract.rs] +//! Demonstrates reading a contract by fetching the WETH balance of an address. +use alloy::{primitives::address, providers::ProviderBuilder, sol}; +use eyre::Result; + +// Generate the contract bindings for the ERC20 interface. +sol! { + // The `rpc` attribute enables contract interaction via the provider. + #[sol(rpc)] + contract ERC20 { + function balanceOf(address owner) public view returns (uint256); + } +} + +#[tokio::main] +async fn main() -> Result<()> { + // Initialize the provider. + let provider = ProviderBuilder::new().connect("https://eth.llamarpc.com").await?; + + // Instantiate the contract instance. + let weth = address!("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"); + let erc20 = ERC20::new(weth, provider); + + // Fetch the balance of WETH for a given address. + let owner = address!("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); + let balance = erc20.balanceOf(owner).call().await?; + + println!("WETH Balance of {owner}: {balance}"); + + Ok(()) +} +``` + +```rust [write_contract.rs] +//! Demonstrates writing to a contract by depositing ETH to the WETH contract. +use alloy::{ + primitives::{ + address, + utils::{format_ether, Unit}, + U256, + }, + providers::ProviderBuilder, + signers::local::PrivateKeySigner, + sol, +}; +use eyre::Result; + +// Generate bindings for the WETH9 contract. +// WETH9: +sol! { + #[sol(rpc)] + contract WETH9 { + function deposit() public payable; + function balanceOf(address) public view returns (uint256); + } +} + +#[tokio::main] +async fn main() -> Result<()> { + // Initialize a signer with a private key. + let signer: PrivateKeySigner = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80".parse()?; + + // Instantiate a provider with the signer. + let provider = ProviderBuilder::new() + // Signs transactions before dispatching them. + .wallet(signer) + // Forking mainnet using anvil to avoid spending real ETH. + .on_anvil_with_config(|a| a.fork("https://eth.llamarpc.com")); + + // Setup WETH contract instance. + let weth = address!("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); + let weth = WETH9::new(weth, provider); + + // Prepare deposit transaction. + let amt = Unit::ETHER.wei().saturating_mul(U256::from(100)); + let deposit = weth.deposit().value(amt); + + // Send the transaction and wait for it to be included. + let deposit_tx = deposit.send().await?; + let receipt = deposit_tx.get_receipt().await?; + + // Check balance by verifying the deposit. + let balance = weth.balanceOf(receipt.from).call().await?; + println!("Verified balance of {:.3} WETH for {}", format_ether(balance), receipt.from); + Ok(()) +} +``` + +```rust [send_transaction.rs] +//! Send a transaction transferring ETH. +use alloy::{ + network::TransactionBuilder, + primitives::{ + address, + utils::{format_ether, Unit}, + U256, + }, + providers::{Provider, ProviderBuilder}, + rpc::types::TransactionRequest, + signers::local::PrivateKeySigner, +}; +use eyre::Result; + +#[tokio::main] +async fn main() -> Result<()> { + // Initialize a signer with a private key. + let signer: PrivateKeySigner = + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80".parse()?; + + // Instantiate a provider with the signer. + // This example uses a local Anvil node. + let provider = ProviderBuilder::new().wallet(signer).connect("http://localhost:8545").await?; + + // Prepare a transaction request to send 100 ETH to Alice. + let alice = address!("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"); + let value = Unit::ETHER.wei().saturating_mul(U256::from(100)); + let tx = TransactionRequest::default().with_to(alice).with_value(value); + + // Send the transaction and wait for the broadcast. + let pending_tx = provider.send_transaction(tx).await?; + println!("Pending transaction... {}", pending_tx.tx_hash()); + + // Wait for the transaction to be included and get the receipt. + let receipt = pending_tx.get_receipt().await?; + println!( + "Transaction included in block {}", + receipt.block_number.expect("Failed to get block number") + ); + + println!("Transferred {:.5} ETH to {alice}", format_ether(value)); + + Ok(()) +} +``` + +::: + + From 7e751e084cd7104101b6ac7dd7f0ded19133fab5 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 11 Apr 2025 19:45:05 +0530 Subject: [PATCH 2/5] feat: landing improvements --- vocs/docs/pages/index.mdx | 91 ++++++++++++++++++++++++++++++++------- vocs/docs/styles.css | 27 ++++++++++++ 2 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 vocs/docs/styles.css diff --git a/vocs/docs/pages/index.mdx b/vocs/docs/pages/index.mdx index 2d6d731..f355937 100644 --- a/vocs/docs/pages/index.mdx +++ b/vocs/docs/pages/index.mdx @@ -1,24 +1,41 @@ --- +title: alloy · TypeScript Interface for Ethereum +content: + width: 100% layout: landing +logo: false --- import { HomePage, Sponsors } from "vocs/components"; import Tab from "../components/Tab"; - - - Connect Applications to Blockchains - - - - - Get started - - - GitHub - - - +
+
+
+
+
+ alloy logo + +
+
Build reliable apps & libraries with lightweight, composable, and type-safe modules that interface with Ethereum
+
+ Get started + GitHub +
+
+
+ ```bash [cargo] + cargo add alloy + ``` +
+
+ +
+
+ +
+ +# Common Actions :::code-group @@ -160,4 +177,48 @@ async fn main() -> Result<()> { ::: - +# Features + +viem supports all these features out-of-the-box: + +- Abstractions over the [JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/) to make your life easier +- First-class APIs for interacting with [Smart Contracts](https://ethereum.org/en/glossary/#smart-contract) +- Language closely aligned to official [Ethereum terminology](https://ethereum.org/en/glossary/) +- Import your Browser Extension, WalletConnect or Private Key Wallet +- Browser native [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), instead of large BigNumber libraries +- Utilities for working with [ABIs](https://ethereum.org/en/glossary/#abi) (encoding/decoding/inspection) +- TypeScript ready ([infer types](/docs/typescript) from ABIs and EIP-712 Typed Data) +- First-class support for [Anvil](https://book.getfoundry.sh/), [Hardhat](https://hardhat.org/) & [Ganache](https://trufflesuite.com/ganache/) +- Test suite running against [forked](https://ethereum.org/en/glossary/#fork) Ethereum network + +# Community + +Check out the following places for more wagmi-related content: + +- Follow [@wevm_dev](https://twitter.com/wevm_dev), [@\_jxom](https://twitter.com/_jxom), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates +- Join the [discussions on GitHub](https://github.com/wevm/viem/discussions) +- [Share your project/organization](https://github.com/wevm/viem/discussions/104) that uses viem + +# Support + +Help support future development and make wagmi a sustainable open-source project: + +- [GitHub Sponsors](https://github.com/sponsors/wevm?metadata_campaign=docs_support) +- [Gitcoin Grant](https://wagmi.sh/gitcoin) +- [wevm.eth](https://etherscan.io/enslookup-search?search=wevm.eth) + +# Sponsors + +::sponsors + + + +
diff --git a/vocs/docs/styles.css b/vocs/docs/styles.css new file mode 100644 index 0000000..5d934fa --- /dev/null +++ b/vocs/docs/styles.css @@ -0,0 +1,27 @@ +@import "tailwindcss" important; + +@custom-variant dark (&:where(.dark, .dark *)); + +[data-layout="landing"] .vocs_Button_button { + border-radius: 4px !important; + height: 36px !important; + padding: 0 16px !important; +} + +[data-layout="landing"] .vocs_Content { + position: inherit; +} + +#home-install .vocs_CodeGroup { + display: flex; + height: 100%; + flex-direction: column; +} + +#home-install .vocs_Tabs_content { + flex: 1; +} + +#home-install .vocs_Code { + font-size: 18px; +} From 1def579d81812b82f8ba930e2f046e52c50c040d Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 11 Apr 2025 19:48:05 +0530 Subject: [PATCH 3/5] nits --- vocs/docs/pages/index.mdx | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/vocs/docs/pages/index.mdx b/vocs/docs/pages/index.mdx index f355937..d3d4342 100644 --- a/vocs/docs/pages/index.mdx +++ b/vocs/docs/pages/index.mdx @@ -1,5 +1,5 @@ --- -title: alloy · TypeScript Interface for Ethereum +title: alloy · Rust Ethereum content: width: 100% layout: landing @@ -199,26 +199,6 @@ Check out the following places for more wagmi-related content: - Join the [discussions on GitHub](https://github.com/wevm/viem/discussions) - [Share your project/organization](https://github.com/wevm/viem/discussions/104) that uses viem -# Support - -Help support future development and make wagmi a sustainable open-source project: - -- [GitHub Sponsors](https://github.com/sponsors/wevm?metadata_campaign=docs_support) -- [Gitcoin Grant](https://wagmi.sh/gitcoin) -- [wevm.eth](https://etherscan.io/enslookup-search?search=wevm.eth) - -# Sponsors - -::sponsors - -
- - Powered by Vercel - -
+ From 0f0d8190e6d9b8e724cc6d4a536a03ecddfd6914 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:38:51 +0530 Subject: [PATCH 4/5] fix --- vocs/docs/pages/index.mdx | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/vocs/docs/pages/index.mdx b/vocs/docs/pages/index.mdx index d3d4342..a7b6785 100644 --- a/vocs/docs/pages/index.mdx +++ b/vocs/docs/pages/index.mdx @@ -14,10 +14,9 @@ import Tab from "../components/Tab";
- alloy logo
-
Build reliable apps & libraries with lightweight, composable, and type-safe modules that interface with Ethereum
+
Connect applications to blockchains using perfomant, intuitive, and battle-tested APIs.
Get started GitHub @@ -177,28 +176,6 @@ async fn main() -> Result<()> { ::: -# Features - -viem supports all these features out-of-the-box: - -- Abstractions over the [JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/) to make your life easier -- First-class APIs for interacting with [Smart Contracts](https://ethereum.org/en/glossary/#smart-contract) -- Language closely aligned to official [Ethereum terminology](https://ethereum.org/en/glossary/) -- Import your Browser Extension, WalletConnect or Private Key Wallet -- Browser native [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), instead of large BigNumber libraries -- Utilities for working with [ABIs](https://ethereum.org/en/glossary/#abi) (encoding/decoding/inspection) -- TypeScript ready ([infer types](/docs/typescript) from ABIs and EIP-712 Typed Data) -- First-class support for [Anvil](https://book.getfoundry.sh/), [Hardhat](https://hardhat.org/) & [Ganache](https://trufflesuite.com/ganache/) -- Test suite running against [forked](https://ethereum.org/en/glossary/#fork) Ethereum network - -# Community - -Check out the following places for more wagmi-related content: - -- Follow [@wevm_dev](https://twitter.com/wevm_dev), [@\_jxom](https://twitter.com/_jxom), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates -- Join the [discussions on GitHub](https://github.com/wevm/viem/discussions) -- [Share your project/organization](https://github.com/wevm/viem/discussions/104) that uses viem - From 0f119078a3e49e07b8c3a29bad4f1a864902645c Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:49:56 +0530 Subject: [PATCH 5/5] top nav --- vocs/docs/components/Tab.tsx | 9 --------- vocs/docs/pages/index.mdx | 3 +-- vocs/vocs.config.tsx | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 11 deletions(-) delete mode 100644 vocs/docs/components/Tab.tsx diff --git a/vocs/docs/components/Tab.tsx b/vocs/docs/components/Tab.tsx deleted file mode 100644 index d688246..0000000 --- a/vocs/docs/components/Tab.tsx +++ /dev/null @@ -1,9 +0,0 @@ -export default function Tab() { - return ( -
- cargo - {' '} - {'add alloy'} -
- ) -} \ No newline at end of file diff --git a/vocs/docs/pages/index.mdx b/vocs/docs/pages/index.mdx index a7b6785..0a493e5 100644 --- a/vocs/docs/pages/index.mdx +++ b/vocs/docs/pages/index.mdx @@ -7,7 +7,6 @@ logo: false --- import { HomePage, Sponsors } from "vocs/components"; -import Tab from "../components/Tab";
@@ -16,7 +15,7 @@ import Tab from "../components/Tab";
-
Connect applications to blockchains using perfomant, intuitive, and battle-tested APIs.
+
Connect applications to blockchains using performant, intuitive, and battle-tested APIs.
Get started GitHub diff --git a/vocs/vocs.config.tsx b/vocs/vocs.config.tsx index 85d3eff..0fca79e 100644 --- a/vocs/vocs.config.tsx +++ b/vocs/vocs.config.tsx @@ -39,5 +39,28 @@ export default defineConfig({ socials: [ { icon: 'github', link: "https://github.com/alloy-rs/alloy" }, { icon: 'telegram', link: "https://t.me/ethers_rs" }, + ], + topNav: [ + { + text: 'Docs', + link: '/getting-started/quick-start', + }, + { + text: 'Examples', + link: 'https://github.com/alloy-rs/examples', + }, + { + text: '0.14.0', + items: [ + { + text: 'Changelog', + link: 'https://github.com/alloy-rs/alloy/blob/main/CHANGELOG.md', + }, + { + text: 'Contributing', + link: 'https://github.com/alloy-rs/alloy/blob/main/CONTRIBUTING.md', + }, + ], + }, ] })