title | weight | menu | ||||
---|---|---|---|---|---|---|
FAQ |
3001 |
|
You can post your questions to
- Substrate and Polkadot StackExchange, remember to add the
phat-contract
tag; - or join our Discord server and get an immediate response in the
#dev
channel.
- Now 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.
Upgrade cargo-contract to version 1.5.2 or higher once this PR has been merged.
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:
- Use the crate pink-json instead of
serde_json
. - 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" }
TODO