pythonblockchainnodestontvm

Invalid Destination address in outbound message. Ton blockchain


i have problem with sending message to Ton blockchain but I'm sure my code is True and it should work here is my code :

    async def deposit(self, amount, to_address, comment=None, token=None, fee=0.06):
        try:
            wallet = self.import_wallet()
            seqno = self.get_seqno()
            if token:
                token_address = self.client.define_token(**token)[0]["owner_address"]
                body = JettonWallet().create_transfer_body(
                    to_address=Address(to_address),
                    jetton_amount=amount * 10 ** 9
                )
                query = wallet.create_transfer_message(
                    to_addr=token_address,
                    seqno=seqno,
                    payload=body,
                    amount=fee * 10 ** 9
                )["message"].to_boc(False)

            else:
                query = wallet.create_transfer_message(
                    to_addr=to_address,
                    amount=to_nano(amount, "ton"),
                    payload=comment if comment else "no message",
                    seqno=seqno,
                    send_mode=3
                )["message"].to_boc(False)

            client = await self.ton_client.get_client(index=5)
            await client.raw_send_message(query)
            return "Deposit successful."

        except Exception as e:
            return f"Failed to send deposit: {e}"
        finally:
            await client.close()

i try anything in this course said :

https://github.com/TonDevStudy/pyton-lessons-eng/tree/main

Gere is my hole error:

{
    "response": "Failed to send deposit: LITE_SERVER_UNKNOWN: cannot apply external message to current state : External message was not accepted\nCannot run message on account: inbound external message rejected by transaction 0332CEA4C9A11B46D22461E4C5DB6CDB885DBAEB73C60BB00F71C200D5C21E29:\nexitcode=36, steps=13, gas_used=0\nVM Log (truncated):\n...CTPUSHCONST 19 (xC_,1)\nexecute DICTIGETJMPZ\nexecute PUSHPOW2 9\nexecute LDSLICEX\nexecute DUP\nexecute LDU 32\nexecute LDU 32\nexecute LDU 32\nexecute XCHG s2\nexecute NOW\nexecute LEQ\nexecute THROWIF 36\ndefault exception handler, terminating vm with exit code 36\n"
}

Solution

  • I found it.

    in the tonlibClient library, I found a new argument named loop and i never used this before.

    here is the tested code:

        async def deposit(self, amount, to_address, comment=None, token=None, fee=0.06):
        try:
            ton_client = await self.ton_client.get_client(index=5)
            wallet = self.import_wallet()
            seqno = self.get_seqno()
            if token:
                token_address = self.client.define_token(**token)[0]["owner_address"]
                body = JettonWallet().create_transfer_body(
                    to_address=Address(to_address),
                    jetton_amount=amount * 10 ** 9
                )
                query = wallet.create_transfer_message(
                    to_addr=token_address,
                    seqno=seqno,
                    payload=body,
                    amount=fee * 10 ** 9
                )["message"]
    
            else:
                query = wallet.create_transfer_message(
                    to_addr=to_address,
                    amount=to_nano(float(amount), 'ton'),
                    payload=comment,
                    seqno=seqno,
                    send_mode=3
                )['message']
    
            await ton_client.raw_send_message(query.to_boc(False))
            return "Deposit successful."
    
        except Exception as e:
            return f"Failed to send deposit: {e}"
        finally:
            await ton_client.close()
    

    the change phrase is on the tonlibClient:

        async def get_client(self, index: int = 0, timeout=10):
        loop = asyncio.get_running_loop()
        ton_config = requests.get(self.ton_config_url).json()
        Path(self.keystore_dir).mkdir(parents=True, exist_ok=True)
        client = TonlibClient(ls_index=index, config=ton_config, keystore=self.keystore_dir, tonlib_timeout=timeout,
                              loop=loop)
        await client.init()
        return client