spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
341 stars 142 forks source link

Insufficient input in transaction #61

Closed Floatiez closed 2 years ago

Floatiez commented 2 years ago

I am using a wallet on the testnet with 220 tADA on 2 UTxOs. This is a single address wallet. I am trying to send a 50 tADA transaction to another wallet using lucid. I am building the entropy from a mnemonic.

This is what I have for building the tx:

const lucid = await Lucid.new(
            new Blockfrost('https://cardano-testnet.blockfrost.io/api/v0', 'testnet63vSq.....odkACx5'),
            'Testnet'
);
const rootKey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(
            Buffer.from(entropy, 'hex'),
            Buffer.from(''),
);

const privateKey = rootKey.to_raw_key().to_bech32();

ucid.selectWalletFromPrivateKey(privateKey);

const lovelaces = parseInt(requestedAmount, 10) * 1000000.0;

const tx = await lucid.newTx()
            .payToAddress(receiveAddress, {lovelace: lovelaces})
            .complete();

const signedTx = await tx.sign().complete();

const txHash = await signedTx.submit();

console.log(txHash);

I get the error: Insufficient input in transaction

I dont understand why there is insufficient input if I have more than 50 tADA in the wallet? Does this not automatically select UTxOs for input?

alessandrokonrad commented 2 years ago

You need to derive the private key from the root key. Just follow the correct derivation path according to the standards. Also keep in mind that if you select a wallet from a private key you end up creating an Enterprise Addess without the staking key part. So if you have the funds locked at an address with a staking key then Lucid will not see those UTxOs.

Floatiez commented 2 years ago

Is this line const privateKey = rootKey.to_raw_key().to_bech32(); not deriving the private key from the root key? Would there not be a way to use just a regular address with stake key instead of an enterprise address?

Floatiez commented 2 years ago

I was able to get it working using the enterprise address generated at lucid.wallet.address(). Transactions will submit and post to the blockchain, but sometimes if I submit multiple tx in a row I get this:

Error: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash \"5229a19dde7e37fa60dfcbb438165e43fe3d811ae4c7df513ed28107\")) StakeRefNull,Value 168090 (fromList [(PolicyID {policyID = ScriptHash \"8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3\"},fromList [(666c6f617469657a,1)])]),NoDatum,SNothing),Coin 1034400)]))])"
    at Blockfrost._callee8$ (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:3296:21)
    at tryCatch (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:141:40)
    at Generator.invoke [as _invoke] (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:372:22)
    at Generator.next (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:197:21)
    at asyncGeneratorStep (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:3:24)
    at _next (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:25:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Floatiez commented 2 years ago

I was able to get it working using the enterprise address generated at lucid.wallet.address(). Transactions will submit and post to the blockchain, but sometimes if I submit multiple tx in a row I get this:

Error: "transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash \"5229a19dde7e37fa60dfcbb438165e43fe3d811ae4c7df513ed28107\")) StakeRefNull,Value 168090 (fromList [(PolicyID {policyID = ScriptHash \"8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3\"},fromList [(666c6f617469657a,1)])]),NoDatum,SNothing),Coin 1034400)]))])"
    at Blockfrost._callee8$ (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:3296:21)
    at tryCatch (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:141:40)
    at Generator.invoke [as _invoke] (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:372:22)
    at Generator.next (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:197:21)
    at asyncGeneratorStep (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:3:24)
    at _next (file:///var/task/lucid/node_modules/lucid-cardano/dist/index.js:25:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

>

This was solved by ensuring the min amount of $tADA that accompanies any UTXO with a token is atleast 2. Something wrong with blockfrost API, not sure what exactly.

jonathanfishbein1 commented 1 year ago

I seem to be experiencing this issue while trying to spend the funds here

[https://preview.cardanoscan.io/address/60eefb5b9dbac4a380296de0655f6ace6c97e9b981eef89a7bf53dcd52]()

That is the address I get when I do lucid.wallet.address() and it doesnt have a staking componenet. I believe all my outputs have the minimum ada amount for all that have native tokens attached. This is a multisignature tx and it seems to be working fine on the client. This error is appearing on the server

jonathanfishbein1 commented 1 year ago

I seem to be experiencing this issue while trying to spend the funds here

https://preview.cardanoscan.io/address/60eefb5b9dbac4a380296de0655f6ace6c97e9b981eef89a7bf53dcd52

That is the address I get when I do lucid.wallet.address() and it doesnt have a staking componenet. I believe all my outputs have the minimum ada amount for all that have native tokens attached. This is a multisignature tx and it seems to be working fine on the client. This error is appearing on the server

I'm good