sendwithmetadata error Insufficient funds - different outputs with same method

+2 votes

I want to use Data Stream as a append-only log, when testing the method sendwithmetadata following the guide of the doc the website provided. At first, things works well, but after executions of sendwithmetadata many time, suddenly I found an error occurs: 

testchain: sendwithmetadata 1AxyjHveM5qHAabj494HHEgVny3iX3KyUfKjUh 0 123454321

error code: -4
error message:
Insufficient funds, but there are coins belonging to addresses without send permission or P2SH addresses.

Using the multichain-explorer,I found a  sendwithmetadata method normally creates a transaction(I name this kind tx as sendwithmetadata transaction) with three outputs:

When executing a new sendwithmetadata method, the third output of  former sendwithmetadata transaction will be redeemed, and the new sendwithmetadata transaction  also has three output.

But, when the error occurs, I found the sendwithmetadata transaction only have two outputs, so next time when I execute sendwithmetadata method, I have no "unspend" output to redeem, which make the error happen.I recreate a new chain and test sendwithmetadata many times, untill now there is no such error. I'm confused now.

so my question is  why there are different transaction outputs for the same method sendwithmetadata, and is there some  trick I don't know when execute sendwithmetadata, or this is just a bug?

asked Aug 9, 2016 by binta

1 Answer

+2 votes
Best answer

I think the problem may have happened because you had an address with send permission but without receive permission, so a change output could not be added back to the same address. Does that make sense? You can exercise more control over which address is used with the sendwithmetadatafrom API, and you can ensure that address has both send and receive permission.

answered Aug 9, 2016 by MultiChain
selected Aug 9, 2016 by binta
It does make sense.I check the permission and found it's the reason you mentioned.Thanks a lot !