FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.4k stars 1.32k forks source link

Add `createAssetId` function #2646

Closed matt-user closed 14 hours ago

matt-user commented 4 days ago

Motivation

Creating an assetId manually is easy, but is also easy to mess up. For new devs this function would be helpful.

Summary

Usage example

const assetId = createAssetId(contractId, subId)

Possible implementations

function createAssetId(contractId: string, subId: string) {
    const contractIdBytes = arrayify(contractId);
    const subIdBytes = arrayify(subId);
    const bits = sha256(concat([contractIdBytes, subIdBytes]));
    const assetId: AssetIdInput = {
        bits
    }
    return assetId
}
petertonysmith94 commented 4 days ago

Could this be an extension of getMintedAssetId?

Torres-ssf commented 1 day ago

@matt-user We already have the helper getMintesAssetId that hashes both the contractId and the subId to return the assetId

bolajahmad commented 1 day ago

I agree with @Torres-ssf, there is already the getMintedAsset that returns pretty much the assetId and is the same function I had to use when writing the createAssetId. They are also located in the same file

Is there some special feature of the new createAssetId.