![](/img/trans.png)
[英]Rust ink, Unable to use imported module due an "unresolved import" error
[英]Rust ink, cross contract call returns ConctractTrapped error
正如標題所暗示的那樣,我試圖在已部署的合同上調用 function,並返回一個非常簡單的字符串 function。
已部署合約 1 function:
#[ink(message)]
#[ink(selector = 0xDEADBEEF)]
pub fn test(&self) -> String {
return "TEST".to_string()
}
下面的代碼片段是contract2 function,從contract1返回值:
#[ink(message)]
pub fn test1(&self,token_contract: AccountId) -> String {
let my_return_value: String = ink_env::call::build_call::<ink_env::DefaultEnvironment>()
.callee(token_contract)
.gas_limit(50000)
.transferred_value(0)
.exec_input(
ink_env::call::ExecutionInput::new(ink_env::call::Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
)
.returns::<ink_env::call::utils::ReturnType<String>>()
.fire()
.unwrap();
my_return_value
}
這意味着你的子合約,也就是持有“pub fn test”的合約已經恐慌了。
調試它的方法是啟動你的底層節點:
RUST_LOG=runtime=debug
通過這種方式,您將在基板日志中獲得准確的恐慌錯誤。
如果你想處理調用者合約中的錯誤,build_call has map_err function。你可以查看他們的多重簽名示例以獲取代碼參考: https://github.com/paritytech/ink/blob/master/examples/multisig/lib.rs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.