# Problem sending messages from a contract

**URL:** <https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206>\
**Category:** Developers\
**Created:** [17 March 2021 19:36 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206 "2021-03-17T19:36:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Malnemark](https://talk.jelurida.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Malnemark](https://talk.jelurida.com/u/Malnemark)\
**Post date:** [17 March 2021 19:36 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/1 "2021-03-17T19:36:13Z")

</div>

Hi devs,  
i am sending messages from a smart contract, and later, in subsequent blocks, I want to read them back, by the same contract, to react. I basically use the message function to store data "persistently" for a few blocks. To keep the contract itself stateless. I see that the message is submitted in the log, but I'm not able to retrieve it back using a getPrunableMessages call. I guess I make a mistake somewhere, and probably an obvious one.

In block X, I send this message:

> SendMessageCall sendMessageCall = SendMessageCall.create(2).  
> message(message.toJSONString()).  
> messageIsPrunable(true).  
> feeNQT(IGNIS.ONE\_COIN).  
> recipient(otherAccountRs);  
> context.createTransaction(sendMessageCall);

The node responds:

> 2021-03-17 08:02:22 INFO: main [sendMessage]: request broadcast=false&chain=2&requestType=sendMessage&messageIsPrunable=true&feeNQT=100000000&recipient=9753781029058255917&ecBlockHeight=8&publicKey=112e0c5748b5ea610a44a09b1ad0d2bddc945a6ef5edc7551b80576249ba585b&message={"submittedBy":"myContract","value1":false,"contract":"myContract","importantHeight":X,"source":"BLOCK"}&ecBlockId=5755268534631000133&timestamp=101668395  
> 2021-03-17 08:02:22 INFO: main [sendMessage]: request broadcast=true&chain=2&requestType=sendMessage&messageIsPrunable=true&feeNQT=2000000&recipient=9753781029058255917&ecBlockHeight=8&publicKey=112e0c5748b5ea610a44a09b1ad0d2bddc945a6ef5edc7551b80576249ba585b&message={"submittedBy":"myContract","value1":false,"contract":"myContract","importantHeight":X,"source":"BLOCK"}&ecBlockId=5755268534631000133&timestamp=101668395

Note the change in fees between both rows.

In block X+1..n, using the same callback (processBlock), I want to check for this message:

> JO response = GetPrunableMessagesCall.create(2).account(context.getAccountRs()).otherAccount(otherAccountNumeric).timestamp(timeOfABlockBeforeX).call();

And I don't find any messages.

- Later,I tried without the timestamp in the GetPrunableMessagesCall, to no avail, unfortunately.
- Checking for messages in the test that runs the contract also returns no messages.
- I tried adding a message to the sendMoneyCall, which also didnt modify the standard {"submittedBy":"myContract","source":"BLOCK"} message.

thanks for any help!

---

<div class="post-metadata">

**Author:** ![sergi](https://talk.jelurida.com/user_avatar/talk.jelurida.com/sergi/32/21_2.png) [@sergi](https://talk.jelurida.com/u/sergi)\
**Post date:** [18 March 2021 07:40 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/2 "2021-03-18T07:40:42Z")

</div>

Are you running all of this code from the same unit test? Notice that each unit test starts with an empty blockchain (there's a reset between tests).

---

<div class="post-metadata">

**Author:** ![sergi](https://talk.jelurida.com/user_avatar/talk.jelurida.com/sergi/32/21_2.png) [@sergi](https://talk.jelurida.com/u/sergi)\
**Post date:** [18 March 2021 07:41 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/3 "2021-03-18T07:41:47Z")

</div>

Perhaps you can share the full log of the unit test run, we output quite some information to debug what's happening.

---

<div class="post-metadata">

**Author:** ![Malnemark](https://talk.jelurida.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Malnemark](https://talk.jelurida.com/u/Malnemark)\
**Post date:** [18 March 2021 20:31 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/4 "2021-03-18T20:31:44Z")

</div>

Hi Sergi,

I think I found the root cause of the issue.  
replacing

> context.createTransaction(sendMessageCall);

with

> return context.createTransaction(sendMessageCall);

solved the issue.

To send multiple messages I have to return context.getResponse(). That wasn't obvious to me. Thanks for the support

---

<div class="post-metadata">

**Author:** ![Malnemark](https://talk.jelurida.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Malnemark](https://talk.jelurida.com/u/Malnemark)\
**Post date:** [13 May 2021 07:30 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/5 "2021-05-13T07:30:22Z")

</div>

Hi Jelurida, could you review that section of the docs in the context above? I think that the documentation misses the bit that you need to either return "getResponse()" or the "createTransaction()".

> **[Submitting Transactions - Lightweight Contracts](https://ardordocs.jelurida.com/Lightweight_Contracts#Submitting_Transactions)**
>
> In most cases, contracts should not save any internal state between contract invocations. To make changes to the blockchain state, contracts should submit transactions. To submit a transaction, invoke the API caller for the specific transaction type,...

---

<div class="post-metadata">

**Author:** ![sergi](https://talk.jelurida.com/user_avatar/talk.jelurida.com/sergi/32/21_2.png) [@sergi](https://talk.jelurida.com/u/sergi)\
**Post date:** [15 May 2021 07:28 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/6 "2021-05-15T07:28:04Z")

</div>

I'm adding a note to my backlog to take a look into it as soon as possible.

---

<div class="post-metadata">

**Author:** ![sergi](https://talk.jelurida.com/user_avatar/talk.jelurida.com/sergi/32/21_2.png) [@sergi](https://talk.jelurida.com/u/sergi)\
**Post date:** [17 May 2021 06:52 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/7 "2021-05-17T06:52:45Z")

</div>

I'm reviewing the docs about this. I have one question: if you weren't returning the context (either from `createTransaction()` or from `getResponse()` what were your returning instead?

---

<div class="post-metadata">

**Author:** ![Malnemark](https://talk.jelurida.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@Malnemark](https://talk.jelurida.com/u/Malnemark)\
**Post date:** [22 May 2021 04:51 UTC](https://talk.jelurida.com/t/problem-sending-messages-from-a-contract/206/8 "2021-05-22T04:51:05Z")

</div>

I had to go back through my commits: I returned a self-made JO with some information, to add this information to the node log.
