Open dengshuaige opened 8 months ago
Compilation Errors in Rust Error 1: Size for [u8] not known at compile-time
rust Copy code error[E0277]: the size for values of type [u8] cannot be known at compilation time --> core/lib/storage/src/chain/operations_ext/mod.rs:1444:15 | 1444 | .map(|account| (start_account, Address::from_slice(&account))) Solution: This error is related to Rust's safety mechanisms around data sizes. [u8] is a slice with an unknown size at compile time. Ensure that Address::from_slice is designed to take a slice (&[u8]) rather than a fixed array. This change should make the function compatible with dynamic slice sizes:
rust Copy code impl Address { pub fn from_slice(slice: &[u8]) -> Self { // Your code here } } Error 2: Type annotations needed
rust
Copy code
error[E0282]: type annotations needed for Vec
rust
Copy code
let mut account_diff: Vec
rust Copy code error[E0609]: no field fromblock on type & --> core/lib/storage/src/ethereum/mod.rs:520:46 | 520 | ... let (from_block, to_block) = (op.from_block as u32, op.to_block as u32)... Solution: Check the structure you're accessing (op). It seems op does not have a from_block field. You need to ensure that op is correctly typed and indeed contains this field. If op is intended to be a struct or a type with this field, verify that you're using the correct type and importing all necessary modules.
Warnings: Unused Imports These are less critical but cleaning them up will make your codebase cleaner and more efficient.
rust Copy code warning: unused import: num::bigint::ToBigInt warning: unused import: num::ToPrimitive Solution: Remove unused imports:
rust Copy code // Remove these lines if the imports are not used // use num::bigint::ToBigInt; // use num::ToPrimitive; Issue with Typechain You mentioned that the deployment fails because it can't find "typechain." Typechain is a tool that generates TypeScript bindings for Ethereum smart contracts, which helps in interacting with contracts in a type-safe way.
Solution:
Ensure Typechain Installation:
Make sure Typechain is installed in your project. You can add it via npm or yarn if it's missing: bash Copy code npm install --save-dev typechain @typechain/ethers-v5 or
bash Copy code yarn add --dev typechain @typechain/ethers-v5 Generate Typechain Artifacts:
After installation, you may need to generate or regenerate Typechain artifacts. This typically involves a command like: bash Copy code npx typechain --target ethers-v5 'src/*/.json' Adjust the path to match where your contract ABI .json files are stored.
Check Typechain Configuration:
Ensure your project's configuration files (like tsconfig.json for TypeScript) are set up to include the Typechain output directories and that these are correctly referenced in your deployment scripts. By following these steps, you should resolve the compilation issues and the missing Typechain dependency, allowing your contract deployment to proceed without errors.
When I finished "zk init", use the "zk contract deploy", it returns can't find typechain, the returns:
[u8]
cannot be known at compilation time --> core/lib/storage/src/chain/operations_ext/mod.rs:1444:15Vec<T>
--> core/lib/storage/src/chain/state/mod.rs:623:17help: consider giving = Vec::new();
| ++++++++
account_diff
an explicit type, where the type for type parameterT
is specified | 623 | let mut account_diff: Vecerror[E0609]: no field
from_block
on type&_
--> core/lib/storage/src/ethereum/mod.rs:520:46 | 520 | ... let (from_block, to_block) = (op.from_block as u32, op.to_block a... | ^^^^^^^^^^warning: unused import:
num::bigint::ToBigInt
--> core/lib/storage/src/chain/account/mod.rs:24:5 | 24 | use num::bigint::ToBigInt; | ^^^^^^^^^^^^^^^^^^^^^warning: unused import:
num::ToPrimitive
--> core/lib/storage/src/misc/mod.rs:9:5 | 9 | use num::ToPrimitive; | ^^^^^^^^^^^^^^^^Some errors have detailed explanations: E0277, E0282, E0609. For more information about an error, try
rustc --explain E0277
. warning:zksync_storage
(lib) generated 21 warnings error: could not compilezksync_storage
(lib) due to 319 previous errors; 21 warnings emitted