<p>You need to do something like this:</p>
<pre class="lang-js prettyprint-override"><code>    /**
     * The collateral is need for working with Plutus Scripts
     * Essentially you need to provide collateral to pay for fees if the
     * script execution fails after the script has been validated...
     * this should be an uncommon occurrence and would suggest the smart contract
     * would have been incorrectly written.
     * The amount of collateral to use is set in the wallet
     * @returns {Promise&lt;void&gt;}
     */
    getCollateral = async () =&gt; {

        let CollatUtxos = [];

        try {

            let collateral = [];

            const wallet = this.state.whichWalletSelected;
            if (wallet === &quot;nami&quot;) {
                collateral = await this.API.experimental.getCollateral();
            } else {
                collateral = await this.API.getCollateral();
            }

            for (const x of collateral) {
                const utxo = TransactionUnspentOutput.from_bytes(Buffer.from(x, &quot;hex&quot;));
                CollatUtxos.push(utxo)
                // console.log(utxo)
            }
            this.setState({CollatUtxos})
        } catch (err) {
            console.log(err)
        }

    }
</code></pre>
<p>There is a working example in this repo:
<a href="https://github.com/dynamicstrategies/cardano-wallet-connector" rel="nofollow noreferrer">https://github.com/dynamicstrategies/cardano-wallet-connector</a></p>

CC BY-SA 4.0
2022-12-02T11:11:48.303Z
2022-12-02T11:11:48.303Z
D S
<p>I am using the function cardano.getCollateral() in the nami wallet library which gives me the utxo of a collateral, lets say it is: &quot;8282582059aca4594629e55a25e2ef20ac8b58fe65a946f215639dbde038f598d0f25a040082583900b9e79b67bc322d4d9b0a2d5449353e58f22aeea3bd349cdd363543fc4ec0b90c580c1091a8bc26989d288402ed015c1c747d5290698a15f41a004c4b40&quot;.</p>
<p>How can i go get from this the utxo of the collateral or the transaction ID in cardano-client-lib?</p>
<p>Thank you</p>

<cardano-cli><nami-wallet><utxo><collateral>
Get UTXO or tnx hash from nami Collateral
# Get UTXO or tnx hash from nami Collateral

(Asked by: username_0 on 2022-03-24)

I am using the function cardano.getCollateral() in the nami wallet library which gives me the utxo of a collateral, lets say it is: "8282582059aca4594629e55a25e2ef20ac8b58fe65a946f215639dbde038f598d0f25a040082583900b9e79b67bc322d4d9b0a2d5449353e58f22aeea3bd349cdd363543fc4ec0b90c580c1091a8bc26989d288402ed015c1c747d5290698a15f41a004c4b40".

How can i go get from this the utxo of the collateral or the transaction ID in cardano-client-lib?

Thank you

**Tags:** cardano-cli, nami-wallet, utxo, collateral

---

## 1 answers

### Answer by username_1 on 2022-12-02. Score: 1

You need to do something like this:
    /**
     * The collateral is need for working with Plutus Scripts
     * Essentially you need to provide collateral to pay for fees if the
     * script execution fails after the script has been validated...
     * this should be an uncommon occurrence and would suggest the smart contract
     * would have been incorrectly written.
     * The amount of collateral to use is set in the wallet
     * @returns {Promise}
     */
    getCollateral = async () => {

        let CollatUtxos = [];

        try {

            let collateral = [];

            const wallet = this.state.whichWalletSelected;
            if (wallet === "nami") {
                collateral = await this.API.experimental.getCollateral();
            } else {
                collateral = await this.API.getCollateral();
            }

            for (const x of collateral) {
                const utxo = TransactionUnspentOutput.from_bytes(Buffer.from(x, "hex"));
                CollatUtxos.push(utxo)
                // console.log(utxo)
            }
            this.setState({CollatUtxos})
        } catch (err) {
            console.log(err)
        }

    }

There is a working example in this repo:
https://github.com/dynamicstrategies/cardano-wallet-connector


---

