pub fn create_new_better_payment(
            &mut self,
            _value: Balance,
            _arbiter_provider: AccountId,
            _deadline: u64,
            //this deadline is deadline that will be added to current time once the audit is assigned to an auditor.
        ) -> Result<()> {
            let _now = self.env().block_timestamp();
            let x = PaymentInfo {
                value: _value,
                starttime: _now,
                auditor: self.env().caller(),
                arbiterprovider: _arbiter_provider,
                patron: self.env().caller(),
                deadline: _deadline,
                currentstatus: AuditStatus::AuditCreated,
            assert_ne!(_value, 0);
            let xyz = ink::env::call::build_call::<Environment>()
            if xyz {
                self.env().emit_event(TokenIncoming {
                    id: self.current_audit_id,
                    .insert(&self.current_audit_id, &x);
                self.env().emit_event(AuditInfoUpdated {
                    id: Some(self.current_audit_id),
                    payment_info: Some(x),
                    updated_by: Some(self.env().caller()),
                self.current_audit_id = self.current_audit_id + 1;
                return Ok(());
            } else {
                return Err(Error::InsufficientBalance);

Why is this function misbehaving?

I am trying to send the caller's ERC20 tokens to this contract in the above function, The rest of everything is working, but not the cross-contract calling.

What am I doing wrong here? This function will update the state of its contract but won't transfer the ERC20 tokens of other contract.

1 Answer 1


You need to call approve before transfer_from. Most likely ERC20 contract returned an error. You need to handle errors from the cross contract call.

See more about error handling here and here

  • 1
    I've done the approve part, it is not working.
    – ATV3320
    Commented Aug 23, 2023 at 7:57
  • Than implement an error handling to see an error from ERC20 contract.
    – Bobo K.
    Commented Aug 23, 2023 at 8:01
  • if there were an error on the called contract, wouldn't the whole function fail?
    – ATV3320
    Commented Aug 23, 2023 at 9:54
  • 1
    Unfortunately not, I had the same issue with this contract. Cross contract call didn't fail, but token was not minted because of bad value passed to the call
    – Bobo K.
    Commented Aug 23, 2023 at 10:02
  • Can you suggest the exact changes? I tried this solution but I still can't seem to make it work.
    – ATV3320
    Commented Aug 23, 2023 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.