I am calling the transfer method using cis2Client where i am transferring the funds from the sender to the current contract. But seems like it is failing and i dont know why. How can i print the Cis2ClientError
which is being returned.
To log a message from a smart contract, you need to use the concordium-smart-contract-testing library and set up an integration test.
Maybe you already have this, otherwise several of our examples showcase this.
With this set up, you can use concordium_dbg!
in your smart contract to print strings (example here).
These strings will only show up as part of testing, and if you use print_emitted_events
(example here) and run the tests (cargo concordium test
) with the --allow-debug
flag.
But i want to understand why doesnt Cis2ClientError
implement Reject
so that the error can just be returned from the entrypoint method?
I don’t have a good answer to why it is not implemented, it probably could be.
But you can implement a type wrapping the error and implement Reject for that.
An example of this can be found here
I wrote smtg like this and i guess this is what is needed tbh.
impl From<Cis2ClientError<()>> for Error {
fn from(value: Cis2ClientError<()>) -> Self {
match value {
Cis2ClientError::InvokeContractError(e) => match e {
CallContractError::AmountTooLarge => Self::AmountTooLarge,
CallContractError::MissingAccount => Self::MissingAccount,
CallContractError::MissingContract => Self::MissingContract,
CallContractError::MissingEntrypoint => Self::MissingEntrypoint,
CallContractError::MessageFailed => Self::MessageFailed,
CallContractError::LogicReject { reason, return_value } => Self::LogicReject {
reason,
return_value
},
CallContractError::Trap => Self::Trap,
},
Cis2ClientError::ParseResult => Self::ParseResult,
Cis2ClientError::InvalidResponse => Self::InvalidResponse,
}
}
}
With above, i can just return the error and read it on the client.
A discussion about this can be found here