Trying to create a uniqueId in AS.
I added this package
npm install as-nanoid --save
The nanoid function from the install is as follows:
let urlAlphabet = ['M','o','d','u','l','e','S','y','m','b','h','a','s','O','w','n','P','r','-','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','N','R','V','f','g','c','t','i','U','v','z','_','K','q','Y','T','J','k','L','x','p','Z','X','I','j','Q','W']
export function nanoid(length: number = 21): string {
let id = ''
for (let i = 0; i < length; i++) {
id += urlAlphabet[i32(Math.floor(Math.random() * 64))]
}
return id
}
In my assembly index.ts
file I have the following:
import { nanoid } from 'as-nanoid'
@nearBindgen
class MyClass {
public id: string
constructor() {
this.id = nanoid(8)
}
}
Using NEAR-SDK-AS
When I initialize the contract after deploying it.
near call $CONTRACT init --accountId $CONTRACT
I get the following error:
Error: {"index":0,"kind":{"ExecutionError":"Link Error: Error while importing \"env\".\"seed\": unknown import. Expected Function(FunctionType { params: [], results: [F64] })"}}
Any help here would be appreciated or if there is a simpler way of creating a uniqueId please share.