Replies: 2 comments 3 replies
-
@chriamue did you solve your problem? Your result cannot be finalized as you probably run substrate-contracts-node and in this node blocks are not finalizing. But did you figure out how to properly call method using subxt? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Because the let mut tx_progress = api.tx()
.sign_and_submit_then_watch_default(&payload, &dev::alice())
.await
.unwrap();
// Instead of using the high level `wait_for_finalized_success` API,
// which doesn't help if nothing ever finalizes, we can fall back to
// the "low level" API and wait for the relevant block events instead:
while let Some(ev) = tx_progress.next().await {
// bail if any error encountered with "?".
let ev = ev?;
let block = match ev {
// Finalized! Here we just break the loop but you could return the result of
// `wait_for_success()` too.
TxStatus::InFinalizedBlock(b) | TxStatus::InBestBlock(b) => {
block.wait_for_success().await.unwrap();
break;
},
// Error scenarios; handle the error somehow (below is what Subxt would return).
TxStatus::Error { message } => {
return Err(TransactionError::Error(message).into())
}
TxStatus::Invalid { message } => {
return Err(TransactionError::Invalid(message).into())
}
TxStatus::Dropped { message } => {
return Err(TransactionError::Dropped(message).into())
}
// Ignore and wait for next status event:
_ => continue,
};
} This logic could be wrapped up into a function if you call it a lot for convenience. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I need assistance on how to properly call a contract function in Rust that compiles to wasm. The following methods I've tried aren't functioning as expected.
Based on this example I created a psp22 token contract.
Running contract call which uses subxt works.
cargo contract call --contract 5FmHL1qCfDPQMjzbP9wwXFvdF2GKPP8TqZHLQv5UeuAd6gLn --message PSP22::total_supply --suri //Alice Result Ok(1000000000000000000) Reverted false Your message call has not been executed. To submit the transaction and execute the call on chain, add -x/--execute flag to the command.
When looking into the sources of cargo-contract,
there is a
transcoder.encode(&self.message, &self.args)
function, which seems not too simple to reproduce, as it depends on the compiled contract artifacts.Also the tx_call integration_test is not so easy to understand, how maybe to use the
cargo contract
generated artifacts.An older Stackoverflow answer guided me to this peace of code, that does not work:
The file metadata.scale was created using:
subxt metadata --pallets Contracts,System -f bytes > metadata.scale
.wait_for_finalized_success()
hangs so console log never prints.Beta Was this translation helpful? Give feedback.
All reactions