import { System, Protobuf, StringBytes } from "@koinos/sdk-as"; import { common } from "@koinosbox/contracts"; import { nft } from "@koinosbox/contracts"; export class Nft { _contractId: Uint8Array; /** * Create an instance of a Nft contract * @example * ```ts * const contract = new Nft(Base58.decode("1DQzuCcTKacbs9GGScFTU1Hc8BsyARTPqe")); * ``` */ constructor(contractId: Uint8Array) { this._contractId = contractId; } /** * Get name of the NFT * @external * @readonly */ name(): common.str { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0x82a3537f, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.name': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.str(); return Protobuf.decode(callRes.res.object, common.str.decode); } /** * Get the symbol of the NFT * @external * @readonly */ symbol(): common.str { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0xb76a7ca1, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.symbol': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.str(); return Protobuf.decode(callRes.res.object, common.str.decode); } /** * Get URI of the NFT * @external * @readonly */ uri(): common.str { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0x70e5d7b6, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.uri': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.str(); return Protobuf.decode(callRes.res.object, common.str.decode); } /** * Get name, symbol and decimals * @external * @readonly */ get_info(): nft.info { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0xbd7f6850, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.get_info': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new nft.info(); return Protobuf.decode(callRes.res.object, nft.info.decode); } /** * Get the owner of the collection * @external * @readonly */ owner(): common.address { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0x4c102969, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.owner': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.address(); return Protobuf.decode(callRes.res.object, common.address.decode); } /** * Get total supply * @external * @readonly */ total_supply(): common.uint64 { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0xb0da3934, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.total_supply': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.uint64(); return Protobuf.decode(callRes.res.object, common.uint64.decode); } /** * Get royalties * @external * @readonly */ royalties(): nft.royalties { const argsBuffer = new Uint8Array(0); const callRes = System.call(this._contractId, 0x36e90cd0, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.royalties': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new nft.royalties(); return Protobuf.decode(callRes.res.object, nft.royalties.decode); } /** * Get balance of an account * @external * @readonly */ balance_of(args: nft.balance_of_args): common.uint64 { const argsBuffer = Protobuf.encode(args, nft.balance_of_args.encode); const callRes = System.call(this._contractId, 0x5c721497, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.balance_of': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.uint64(); return Protobuf.decode(callRes.res.object, common.uint64.decode); } /** * Get the owner of a token * @external * @readonly */ owner_of(args: nft.token): common.address { const argsBuffer = Protobuf.encode(args, nft.token.encode); const callRes = System.call(this._contractId, 0xed61c847, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.owner_of': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.address(); return Protobuf.decode(callRes.res.object, common.address.decode); } /** * Get the metadata of a token * @external * @readonly */ metadata_of(args: nft.token): common.str { const argsBuffer = Protobuf.encode(args, nft.token.encode); const callRes = System.call(this._contractId, 0x176c8f7f, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.metadata_of': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.str(); return Protobuf.decode(callRes.res.object, common.str.decode); } /** * Get list of token IDs * @external * @readonly */ get_tokens(args: nft.get_tokens_args): nft.token_ids { const argsBuffer = Protobuf.encode(args, nft.get_tokens_args.encode); const callRes = System.call(this._contractId, 0x7d5b5ed7, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.get_tokens': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new nft.token_ids(); return Protobuf.decode(callRes.res.object, nft.token_ids.decode); } /** * Get tokens owned by an address * @external * @readonly */ get_tokens_by_owner(args: nft.get_tokens_by_owner_args): nft.token_ids { const argsBuffer = Protobuf.encode(args, nft.get_tokens_by_owner_args.encode); const callRes = System.call(this._contractId, 0xfc13eb75, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.get_tokens_by_owner': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new nft.token_ids(); return Protobuf.decode(callRes.res.object, nft.token_ids.decode); } /** * Check if an account is approved to operate a token ID * @external * @readonly */ get_approved(args: nft.token): common.address { const argsBuffer = Protobuf.encode(args, nft.token.encode); const callRes = System.call(this._contractId, 0x4c731020, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.get_approved': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.address(); return Protobuf.decode(callRes.res.object, common.address.decode); } /** * Check if an account is approved to operate all tokens * owned by other account * @external * @readonly */ is_approved_for_all(args: nft.is_approved_for_all_args): common.boole { const argsBuffer = Protobuf.encode(args, nft.is_approved_for_all_args.encode); const callRes = System.call(this._contractId, 0xe7ab8ce5, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.is_approved_for_all': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new common.boole(); return Protobuf.decode(callRes.res.object, common.boole.decode); } /** * Get allowances of an account * @external * @readonly */ get_operator_approvals(args: nft.get_operators_args): nft.get_operators_return { const argsBuffer = Protobuf.encode(args, nft.get_operators_args.encode); const callRes = System.call(this._contractId, 0xdb1bf60e, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.get_operator_approvals': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new nft.get_operators_return(); return Protobuf.decode(callRes.res.object, nft.get_operators_return.decode); } /** * Transfer ownership of the collection * @external * @event collections.owner_event common.address */ transfer_ownership(args: common.address): void { const argsBuffer = Protobuf.encode(args, common.address.encode); const callRes = System.call(this._contractId, 0x394be702, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.transfer_ownership': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Set royalties * @external * @event collections.royalties_event nft.royalties */ set_royalties(args: nft.royalties): void { const argsBuffer = Protobuf.encode(args, nft.royalties.encode); const callRes = System.call(this._contractId, 0x3b5bb56b, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.set_royalties': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Set metadata * @external * @event collections.set_metadata_event nft.metadata_args */ set_metadata(args: nft.metadata_args): void { const argsBuffer = Protobuf.encode(args, nft.metadata_args.encode); const callRes = System.call(this._contractId, 0x3d59af19, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.set_metadata': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Grant permissions to other account to manage a specific Token owned * by the user. The user must approve only the accounts he trust. * @external * @event collections.token_approval_event nft.approve_args */ approve(args: nft.approve_args): void { const argsBuffer = Protobuf.encode(args, nft.approve_args.encode); const callRes = System.call(this._contractId, 0x74e21680, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.approve': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Grant permissions to other account to manage all Tokens owned * by the user. The user must approve only the accounts he trust. * @external * @event collections.operator_approval_event nft.set_approval_for_all_args */ set_approval_for_all(args: nft.set_approval_for_all_args): void { const argsBuffer = Protobuf.encode(args, nft.set_approval_for_all_args.encode); const callRes = System.call(this._contractId, 0x20442216, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.set_approval_for_all': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Transfer NFT * @external * @event collections.transfer_event nft.transfer_args */ transfer(args: nft.transfer_args): void { const argsBuffer = Protobuf.encode(args, nft.transfer_args.encode); const callRes = System.call(this._contractId, 0x27f576ca, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.transfer': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Mint NFT * @external * @event collections.mint_event nft.mint_args */ mint(args: nft.mint_args): void { const argsBuffer = Protobuf.encode(args, nft.mint_args.encode); const callRes = System.call(this._contractId, 0xdc6f17bb, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'Nft.mint': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } }