Development
...
API Reference
Contracts Module
3 min
api reference https //signum network github io/signumjs/modules/contracts html npm package https //www npmjs com/package/@signumjs/contracts cdn url https //cdn jsdelivr net/npm/@signumjs/crypto\@1 0 0 rc 31/dist/signumjs crypto min js https //cdn jsdelivr net/npm/@signumjs/contracts/dist/signumjs contracts min js iife namespace sig$contracts installation npm npm i @signumjs/contracts yarn yarn add @signumjs/contracts \<script/> basic usage the contracts module provides utility functions and classes to interact with signum smart contracts, i e generate method calls, inspect contract data initializes a contracts data stack the following example is an excerpt from the https //github com/signum network/signumjs/tree/main/examples in the github repository see the full example https //github com/signum network/signumjs/blob/main/examples/nodejs/advanced/contracts/viewcontractdata js const {ledgerclientfactory, address} = require('@signumjs/core') const {contractdataview} = require('@signumjs/contracts') // for better readability we use name constants const nftcontractdataindex = { owner 0, status 1, currentprice 2, platformaddress 3, platformfee 4, royaltiesfee 5, royaltiesowner 6, highestbidder 19, totaltimessold 27, totalbidsreceived 28, totalroyaltiesfee 29, totalplatformfee 30, totallikes 31, } // using a dedicated class for contract data view is a nice pattern class nftdataview { constructor(contract) { this id = contract at; // just pass the contract to the viewer class this view = new contractdataview(contract); } getid() { return this id; } getownerid() { return this view\ getvariableasdecimal(nftcontractdataindex owner); } // see the full example here // https //github com/signum network/signumjs/blob/main/examples/nodejs/advanced/contracts/viewcontractdata js } // little helper function asaddress(id, prefix){ return address fromnumericid(id, prefix) getreedsolomonaddress() } async function shownftdata(nftaddress) { try { // here we instantiate the ledger client const ledger = ledgerclientfactory createclient({ nodehost "https //europe signum network" }); // this way we not only convert the contracts address to its id, but this method also asserts // that we have a formally valid address it's not guaranteed that the address really exists in the chain const nftid = address create(nftaddress) getnumericid() const nftcontract = await ledger contract getcontract(nftid) const nftdataview = new nftdataview(nftcontract) console info(`stats of nft '${asaddress(nftid)}'`) console info(' ') console info('creator ', nftcontract creatorrs) console info('current owner ', asaddress(nftdataview\ getownerid(),prefix)) console info('current price ', nftdataview\ getcurrentprice() getsigna(), 'signa') console info('current status ', nftdataview\ getstatus()) console info('number of sales ', nftdataview\ gettotaltimessold()) console info('likes ', nftdataview\ gettotallikes()) // } catch (e) { // if the api returns an exception, // the return error object is of type httperror handleerror(e); } } (async () => { await shownftdata("s pwur hwpd 3grx 8n86v"); })();