user4365: I have a build raw command witch worked very well. But the issue occured when i received some ada for testing purposes
when i run cardano-cli query utxo --address $address --testnet-magic 1097911063 i get this
135cd17e0b9fa7080f9680da51addde5e87ebe9d977536506f37baf9d059677a     0        998685865 lovelace + 234234 1f49b6b44d9c1a8d7b9de0b95247baf757a7280809d144daf6630dc0.asdf + 23423234 30f7743917fb67c65df9689927f716ec368122192d9c6279afc1e958.cool + 234 4d23f4887865b4228a48f59db21d770e6bbc4a94c46c3c96dd72ad3c.asdf + 123123 711c6c84922194c8d2fe43d97769866a35b680c5c6513ac7bf0c19be.sfasfafasdasf + 234 8d4858089e488217d56834fde09d4038f7b675c61fdc883c4efe7934.ölkjasdölfkj + 123123 9c40937c4edf5acad2615b15f4516daad3eefc400913bc563139c5e3.sadfasf + 12234234 c85b75fbfe4810b60d3ff872c0124d811ed637810649800e14371976.asdfasf + TxOutDatumHashNone
23b147e31d0950f1b85b08a35dad87a994b8691598ea071d365248bd3033b50c     0        2391417 lovelace + TxOutDatumHashNone
4f778417a87663e311ff775909f65ba9f8124b4a964313554b8e261a68eca60b     0        2393485 lovelace + TxOutDatumHashNone
9346fa09dab6029344bc531dee5e57ca30d6cdaab04a7fbe69bd86a7d8fc0b9d     0        2007040 lovelace + 11230234 f662fa99ac8c3c9146f12ab34158a4b619c019f38336c3521ecceae1.öasldkfjaösl + TxOutDatumHashNone
a3e7934d43d0f3ae5aedc2d2f14cfb567cb848afc1647d2febe9be5ba1bc6d8b     0        2182573 lovelace + TxOutDatumHashNone
b46316a983cfdf81ed6785d7320feb23547746dea88b04b823c4f5d0d8e32d81     0        5000000 lovelace + TxOutDatumHashNone

This is my function how i build the raw transaction
public buildRaw(date: number,fee: number, address: string, txhash: string, txix: string, output: number, amount: number, policyid: string, tokenname: string,  tokens: { amount: number, tokenHash: string}[]): Promise<string>{
    let matxPath = "matx/" + date + ".raw"
    return new Promise((res, rej) => {
        exec(`cardano-cli transaction build-raw \
        --fee ${fee} \
        --tx-in ${txhash}#${txix} \
        --tx-out ${address}+${output}+"${amount} ${policyid}.${tokenname} ${tokens.reduce((prev, curr) => prev + curr.amount.toString() + ' ' + curr.tokenHash + ' + ', '+ ').slice(0, -2)}" \
        --mint="${amount} ${policyid}.${tokenname}" \
        --minting-script-file policy/${date}.script \
        --out-file ${matxPath}`, (err, data) => {
            if (err) {
                rej(err)
            }
            res(matxPath)
        })
    })
}

I always use the first txhash 135cd17e0b9fa7080f9680da51addde5e87ebe9d977536506f37baf9d059677a with the txix 0
As i said this worked very well. But after i send myself some test ada, as you can see the other transactions, my code does not work anymore. Whats wrong with it?
According to the error i got BadInputs so i guess the problem is in the --tx-in. How do i need structure my --tx-in to make it work?

user4302: Make sure that your tx-hash AND your tx-ix are being updated every time you use the function, especially if change is being sent back to yourself, which would raise the value of your tx-ix

4365: <p>I have a <code>build raw</code> command witch worked very well. But the issue occured when i received some ada for testing purposes</p>
<p>when i run <code>cardano-cli query utxo --address $address --testnet-magic 1097911063</code> i get this</p>
<pre><code>135cd17e0b9fa7080f9680da51addde5e87ebe9d977536506f37baf9d059677a     0        998685865 lovelace + 234234 1f49b6b44d9c1a8d7b9de0b95247baf757a7280809d144daf6630dc0.asdf + 23423234 30f7743917fb67c65df9689927f716ec368122192d9c6279afc1e958.cool + 234 4d23f4887865b4228a48f59db21d770e6bbc4a94c46c3c96dd72ad3c.asdf + 123123 711c6c84922194c8d2fe43d97769866a35b680c5c6513ac7bf0c19be.sfasfafasdasf + 234 8d4858089e488217d56834fde09d4038f7b675c61fdc883c4efe7934.ölkjasdölfkj + 123123 9c40937c4edf5acad2615b15f4516daad3eefc400913bc563139c5e3.sadfasf + 12234234 c85b75fbfe4810b60d3ff872c0124d811ed637810649800e14371976.asdfasf + TxOutDatumHashNone
23b147e31d0950f1b85b08a35dad87a994b8691598ea071d365248bd3033b50c     0        2391417 lovelace + TxOutDatumHashNone
4f778417a87663e311ff775909f65ba9f8124b4a964313554b8e261a68eca60b     0        2393485 lovelace + TxOutDatumHashNone
9346fa09dab6029344bc531dee5e57ca30d6cdaab04a7fbe69bd86a7d8fc0b9d     0        2007040 lovelace + 11230234 f662fa99ac8c3c9146f12ab34158a4b619c019f38336c3521ecceae1.öasldkfjaösl + TxOutDatumHashNone
a3e7934d43d0f3ae5aedc2d2f14cfb567cb848afc1647d2febe9be5ba1bc6d8b     0        2182573 lovelace + TxOutDatumHashNone
b46316a983cfdf81ed6785d7320feb23547746dea88b04b823c4f5d0d8e32d81     0        5000000 lovelace + TxOutDatumHashNone
</code></pre>
<p>This is my function how i build the raw transaction</p>
<pre><code>public buildRaw(date: number,fee: number, address: string, txhash: string, txix: string, output: number, amount: number, policyid: string, tokenname: string,  tokens: { amount: number, tokenHash: string}[]): Promise&lt;string&gt;{
    let matxPath = &quot;matx/&quot; + date + &quot;.raw&quot;
    return new Promise((res, rej) =&gt; {
        exec(`cardano-cli transaction build-raw \
        --fee ${fee} \
        --tx-in ${txhash}#${txix} \
        --tx-out ${address}+${output}+&quot;${amount} ${policyid}.${tokenname} ${tokens.reduce((prev, curr) =&gt; prev + curr.amount.toString() + ' ' + curr.tokenHash + ' + ', '+ ').slice(0, -2)}&quot; \
        --mint=&quot;${amount} ${policyid}.${tokenname}&quot; \
        --minting-script-file policy/${date}.script \
        --out-file ${matxPath}`, (err, data) =&gt; {
            if (err) {
                rej(err)
            }
            res(matxPath)
        })
    })
}
</code></pre>
<p>I always use the first txhash <code>135cd17e0b9fa7080f9680da51addde5e87ebe9d977536506f37baf9d059677a</code> with the txix <code>0</code></p>
<p>As i said this worked very well. But after i send myself some test ada, as you can see the other transactions, my code does not work anymore. Whats wrong with it?</p>
<p>According to the error i got <code>BadInputs</code> so i guess the problem is in the <code>--tx-in</code>. How do i need structure my <code>--tx-in</code> to make it work?</p>
 4302: <p>Make sure that your tx-hash <strong>AND</strong> your tx-ix are being updated every time you use the function, especially if change is being sent back to yourself, which would raise the value of your tx-ix</p>
