Common Issues
- Currently the Phat Contract Console does not support specifying arguments during contract instantiation
- Workaround: you can implement a
config(&mut self, argument0, ...)
function and set the contract state with transactions after the instantiation
The Phat UI checks the contract’s validity before uploading it to the cluster. However, sometimes the contract output by
cargo-contract
may be invalid. We’ve listed common errors and solutions below:or sometimes “use of floating point type in locals is forbidden”
This error occurs when the contract or its dependencies use floating point operations not allowed by the ink runtime.
- To find the source of the problem, try recompiling the contract with
--keep-debug-symbols
, then convert the wasm file to wat usingwasm2wat my_contract.wasm > my_contract.wat
, and search forf32
orf64
in my_contract.wat to find the function using these instructions. - If the floating point operations are necessary, see the section “How to do floating point calculations” for more information.
A common case that introduces FP instructions is parsing JSON in a contract. Either serde or serde_json are designed to be able to handle FP numbers. In theory, if you don’t use it to deal with FP data, the compiler and wasm-opt should be able to optimize the FP instructions away for many cases. However, in practice, if you use serde_json, it always emits FP instructions in the final output wasm file.
If your JSON document contains FP numbers, you can skip this section and go to “How to do floating point calculations” for solutions. If your JSON document does not contain FP numbers, here are some suggestions for removing the instructions:
- Don’t deserialize to
json::Value
orserde::Value
. These are dynamically typed values and make it impossible for the compiler to optimize the code paths that contain FP ops. Instead, mark concrete types with#[derive(Deserialize)]
and deserialize to them directly. - If using
pink-web3
and loadingContract
from its JSON ABI, you may encounter FP problems in a function like_ZN5serde9__private2de7content7Content10unexpected17h5ce9c505c30bc609E
from serde. To fix this, you can patchserde
as shown below.
[patch.crates-io]
serde = { git = "https://github.com/kvinwang/serde.git", branch = "pink" }
2023-07-11T09:42:45.848016Z INFO cargo_contract::crate_metadata: Fetching cargo metadata for Cargo.toml thread 'main' panicked at 'lib name not found', /home/USER/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-contract-1.5.0/src/crate_metadata.rs:65:25 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
After checking the version, it shows:
$ cargo contract --version cargo-contract 1.5.0-unknown-x86_64-unknown-linux-gnu
cargo install --force --locked cargo-contract
Last modified 2mo ago