import { Ecanna, BN, Buffer } from "ecanna/dist" import { TKNVMAPI, KeyChain as TKNVMKeyChain, UTXOSet, UnsignedTx, Tx, MinterSet } from "ecanna/dist/apis/tknvm" import { GetUTXOsResponse } from "ecanna/dist/apis/tknvm/interfaces" import { PrivateKeyPrefix, DefaultLocalGenesisPrivateKey, UnixNow } from "ecanna/dist/utils" const ip: string = "localhost" const port: number = 9650 const protocol: string = "http" const networkID: number = 1337 const ecanna: Ecanna = new Ecanna(ip, port, protocol, networkID) const tknchain: TKNVMAPI = ecanna.TKNChain() const xKeychain: TKNVMKeyChain = tknchain.keyChain() const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}` xKeychain.importKey(privKey) const xAddresses: Buffer[] = tknchain.keyChain().getAddresses() const xAddressStrings: string[] = tknchain.keyChain().getAddressStrings() const threshold: number = 1 const locktime: BN = new BN(0) const asOf: BN = UnixNow() const memo: Buffer = Buffer.from( "TKNVM utility method buildCreateNFTAssetTx to create an NFT" ) const name: string = "non fungible token" const symbol: string = "NFT" const main = async (): Promise => { const tknvmUTXOResponse: GetUTXOsResponse = await tknchain.getUTXOs( xAddressStrings ) const utxoSet: UTXOSet = tknvmUTXOResponse.utxos const minterSets: MinterSet[] = [new MinterSet(threshold, xAddresses)] const unsignedTx: UnsignedTx = await tknchain.buildCreateNFTAssetTx( utxoSet, xAddressStrings, xAddressStrings, minterSets, name, symbol, memo, asOf, locktime ) const tx: Tx = unsignedTx.sign(xKeychain) const txid: string = await tknchain.issueTx(tx) console.log(`Success! TXID: ${txid}`) } main()