Creating Assets
Creating assets
To create any asset, these values must always be filled:
POST /assets/
{
"name": "string",
"author": "string"
}
- name: The visible name of the asset. This is visible for everyone and defines what asset it is. (e.g. “NDA Contract”)
- author: The address that should own this asset. This address must be an Ethereum address that starts with “0x”
After sending a creation request, a new treansaction is generated which is then sent to the defined author address. The asset does not exist in the Blockchain until the user has manually signed and approved the transaction.
Optionally, any asset can also include extra data that can be manually added. Since this is only a normal string, it allows for any text or stringified object like JSON/XML string.
In addition to name
and author
, add the following variable:
{
"data": "string"
}
Asset creation status
As the creation of assets is working in asychronous matter and has a short wait time after accepting the request, the status of the asset can be looked up to optimize automations or show the current state on the UI. The status can be easily looked up by sending GET /assets/{assetId}/status
Attaching file info to assets
Any asset can contain information about a specific file that is connectred with it. Only the metadata is uploaded to the Blockchain, the file itself is managed externally via any option you choose. The asset merely allows the user to compare and confirm that the downloaded file is in connection with the asset.
The comparison mainly happens via the hash string as the user can calculate the hash of the file they downloaded. If it fits with the saved hash from the asset, they can be certain that the file is correct. The hashing method itself is not defined by the Notardec API, any hashing method can be used. In general however, the recommended hashing method should always be used. As of this writing we recommend SHA2-256.
Following variables have to be added in addition to name
and author
:
{
"fileName": "string",
"fileType": "string",
"fileSize": "string",
"method": "string",
"hash": "string",
"uri": "string"
}
- fileName: Name of the file that has been attached. This is to easily fetch and show a user-friendly name.
- fileType: Type of the file e.g. pdf, txt, jpg, …
- fileSize: The size of the file in bytes. This allows the user to compare if the byte size is the same.
- method: Hashing method used. This is important for correct file hash comparison.
- hash: The hash string of the generated hash.
- uri: Optionally define where the file can be downloaded.
Code example
First of all, you need to get your Notardec Key. Then you can use Notardec. For example, let’s create a function that will make a create asset request to Notardec.
export async function createAsset(apiKey: string, token: string | null, payload: CreateAssetRequest): Promise<IResponse<AssetResponse>> {
const result = await axios.post<IResponse<AssetResponse>>(`${process.env.NOTARDEC_URL}/assets`, payload, {
headers: {
'X-API-KEY': apiKey,
Authorization: `Bearer ${token}`,
},
});
return result.data;
}
Here, the first parameter we pass is the Notardec Key, the second is the token (optional parameter, the record can be created using the TEOS key), the third is the asset body. The request body and the response body will have the following form:
Request:
{
name: string;
data?: string;
author: string;
fileName?: string;
fileType?: string;
fileSize?: string;
method?: string;
hash?: string;
uri?: string;
}
Response:
{
value: {
id: string;
author: string;
name: string;
description: string;
language: string;
jurisdiction: string;
unotOfMeasure: string;
sparkFactor: string;
sparkFactorModifier: string;
assetClass: string;
createdOn: Date;
updatedOn: Date;
blockchainHash: string;
documentDbHash: string;
transactionId: string;
customDefinitionItems?: {
key: string;
type: string;
value: string;
name: string;
sectionsPath: string;
sectionsPathNames: string;
}
} || null;
meta ?: {
size ?: number;
page ?: number;
}
error ?: {
code: string;
message: string;
}
}
Then you need to confirm the transaction.
Real asset example
{
id: '0d80c1ea41b73a57db90a0001',
name: 'Hello world asset 1',
author: '0x943d7c1b12d7241598f1bf3fcc5d27a8ad2cc096',
description: 'Notardec Asset',
language: 'en',
jurisdiction: 'EARTH',
unitOfMeasure: 'token',
sparkFactor: '1',
sparkFactorModifier:
'{"type":"FORMULA","start":"2021-09-21T12:11:08Z","t":"1d","f":"1"}',
assetClass: 'A017',
createdOn: '2021-09-21T14:27:44.7828091+02:00',
updatedOn: '2021-09-21T14:27:44.7828091+02:00',
blockchainHash:
'0xa21d0889b90e745516416e13adbb9a8fbfe9fde20e92bd9ee2f728028ae50fcc',
documentDbHash:
'a21d0889b90e745516416e13adbb9a8fbfe9fde20e92bd9ee2f728028ae50fcc',
customDefinitionItems: [
{
key: 'data',
type: 'TEXT',
value: 'Lorem ipsum 111',
name: 'Data',
sectionsPath: '[documentation]',
sectionsPathNames: '[Documentation]',
},
],
transactionId: '03e1da13-aed0-4b46-4708-08d97cc96d25',
assetLinkIds: ['0cf3e2e5f35b8d6cf47aa0001'],
}