DeveryRegistry is the main class to interact with the devery registry. With it you have all the tools that you need to create aps, brands and products. You can use it to mark and check your products and to listen and respond to our protocol events.

Constructor new DeveryRegistry (options) Creates a new DeveryRegistry instance. Usage example: // creates a deveryRegistryClient with the default params let deveryRegistryClient = new DeveryRegistry(); // creates a deveryRegistryClient pointing to a custom address let deveryRegistryClient = new DeveryRegistry({address:'0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'}); Parameters: Name Type Description options ClientOptions network connection options Version: 1 Source: DeveryRegistry.js, line 79

Extends

Methods

(async) brandAccountsPaginated (page opt , pagesize opt ) → {Promise.<Array.<string>>}

Returns an array of brand account addresses from the brandAccounts array contained in the smart contract. If you try to access a page that does not exist you will get a promise that resolves to an empty array as result. These parameters page and pagesize are optional. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.brandAccountsPaginated(0,20).then(addressArr => { for(let address of addressArr) { console.log(address); } }) // or with the async syntax async function foo() { // here we don't pass any param to brandAccountsPaginated // because its parameters are optional let addressArr = await deveryRegistryClient.brandAccountsPaginated(); for(let address of addressArr) { console.log(address); } //... do more stuff } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Default Description page int <optional>

0 the requested page. This parameter is optional, the default value to it is 0. pagesize int <optional>

10 the requested page size. This parameter is optional, the default value to it is 10.

(async) addApp (appName, feeAccount, fee, overrideOptions opt ) → {Promise.<Transaction>}

Creates a new app in the blockchain, each account can have only one account so if your account already have an app you must call updateApp to change its details. This is a write method so you will need to provide some gas to run it, plus keep in mind that your environment need to have access to an signer so make sure that your user have access to metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.addApp("Logistics co. app","0x627306090abaB3A6e1400e9345bC60c78a8BEf57",5).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try{ let transaction = await deveryRegistryClient.addApp("Logistics co. app","0x627306090abaB3A6e1400e9345bC60c78a8BEf57",5); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description appName string your app name feeAccount string the account that will pay the fees for this app transactions fee int the fee amount paid per app transaction overrideOptions TransactionOptions <optional>

gas options to override the default ones

Updates an existing app in the blockchain. This is a write method so you will need to provide some gas to run it, plus keep in mind that your environment need to have access to an signer so make sure that your user have access to metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.updateApp("Logistics co. app","0x627306090abaB3A6e1400e9345bC60c78a8BEf57",5,true).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction') //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.updateApp("Logistics co. app","0x627306090abaB3A6e1400e9345bC60c78a8BEf57",5,true); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description appName string your app name feeAccount string the account that will pay the fees for this app transactions fee int the fee amount paid per app transaction active boolean overrideOptions TransactionOptions gas options to override the default ones

Returns the app with the given address. If the requested app account does not exist then and empty account is returned. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getApp('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(app => { if(app.active) { console.log(app.appName); //... other stuff } }) // or with the async syntax async function foo() { let app = await deveryRegistryClient.getApp('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); if(app.active) { console.log(app.appName); //... other stuff } } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a App you can click here to check its fields

Parameters:

Name Type Description appAccount string address of the request

Returns the app data for the given address. If the requested app account does not exist then an empty app data is returned. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getAppData('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(app => { if(app.active) { console.log(app._appAccount); //... other stuff } }) // or with the async syntax async function foo() { let app = await deveryRegistryClient.getApp('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); if(app.active) { console.log(app._appAccount); //... other stuff } } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a AppData you can click here to check its fields

Parameters:

Name Type Description appAccount string address of the request

(async) appAccountsPaginated (page opt , pagesize opt ) → {Promise.<Array.<string>>}

Returns an array of account addresses from the appAccounts array contained in the smart contract. If you try to access a page that does not exist you will get a promise that resolves to an empty array as result. Parameters page and pageSize are optional. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.appAccountsPaginated(0,20).then(addressArr => { for(let address of addressArr){ console.log(address); } }) // or with the async syntax async function foo() { // here we don't pass any param to appAccountsPaginated // because these parameters are optional let addressArr = await deveryRegistryClient.appAccountsPaginated(); for(let address of addressArr) { console.log(address); } //... do more stuff } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Default Description page int <optional>

0 the requested page. This parameter is optional, the default value to it is 0. pagesize int <optional>

10 the requested page size. This parameter is optional, the default value to it is 10.

(async) appAccountsArray (index) → {Promise.<string>}

Returns an account address from the appAccounts array. If you try to access an index that is out of the array bounds the promise will be rejected. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.appAccountsArray(4).then(address => { deveryClient.getApp(address).then(app => { console.log(app.appName); //... do more stuff }) }).catch(err => { console.log('index ot of bounds'); }) // or with the async syntax async function foo() { try { let accountAddress = await deveryRegistryClient.appAccountsArray(4); let app = await deveryRegistryClient.getApp(accountAddress); if(app.active) { console.log(app.appName); //... other stuff } } catch(err) { console.log('index ot of bounds'); } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description index int the account index inside the appAccounts array

(async) appAccountsLength () → {Promise.<int>}

Returns the total count of app accounts registered on the smart contract. This method is particularly useful to be used in conjunction with appAccountsArray because you can verify the array upper bounds. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.appAccountsLength().then(totalAccounts => { for(let i = 0;i< totalAccounts;i++) { deveryRegistryClient.appAccountsArray(i).then(address => { deveryClient.getApp(address).then(app => { console.log(app.appName); //... do more stuff }) }) } }) // optionally you can use the async syntax if you prefer for more info about how to get a DeveryRegistry instance click here.

setAppAddedEventListener (callback)

Listener to AppAdded events, this event triggers whenever a new devery app is created in the blockchain. Please note, that AppAddedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove an AppAddedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it DeveryRegistryClient.setAppAddedEventListener((appAccount,appName,feeAccount,fee,active) => { // whenever an app created we will log it to the console console.log(`new app created ${appAccount} - ${appName} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter DeveryRegistryClient.setAppAddedEventListener(undefined); // or that is equivalent to the above call DeveryRegistryClient.setAppAddedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback AppEventCallback the callback that will be executed whenever and AppAdded event is triggered

Listener to AppUpdated events, this event triggers whenever an existing devery app is updated in the blockchain. Please note, that AppUpdatedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove an AppUpdatedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it DeveryRegistryClient.setUpdatedEventListener((appAccount,appName,feeAccount,fee,active) => { // whenever an app gets updated we will log it to the console console.log(`an App has been updated ${appAccount} - ${appName} - ${active} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter DeveryRegistryClient.setAppUpdatedEventListener(undefined); // or that is equivalent to the above call DeveryRegistryClient.setAppUpdatedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback AppEventCallback the callback that will be executed whenever and AppUpdated event is triggered

(async) addBrand (brandAccount, brandName, overrideOptions) → {Promise.<Transaction>}

Creates a new brand in the blockchain. Only one brand can exist per account key so keep in mind that. If you try to create more than one brand in the same brand account then you will get an exception. This is a write method, so you will need to provide some gas to run it. Plus keep in mind that your environment needs to have access to a signer, so make sure that your user have access to Metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.addBrand("0x627306090abaB3A6e1400e9345bC60c78a8BEf57","My Brand name").then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')){ console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.addBrand("0x627306090abaB3A6e1400e9345bC60c78a8BEf57","My Brand name"); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description brandAccount string brand account address brandName string the name of the new brand overrideOptions TransactionOptions gas options to override the default ones

Updates an existing brand in the blockchain. This is a write method so you will need to provide some gas to run it, plus keep in mind that your environment need to have access to an signer so make sure that your user have access to metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.updateBrand("0x627306090abaB3A6e1400e9345bC60c78a8BEf57","My Brand name",true).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.updateBrand("0x627306090abaB3A6e1400e9345bC60c78a8BEf57","My Brand name",true); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description brandAccount string brand account address brandName string the name of the new brand active boolean overrideOptions TransactionOptions gas options to override the default ones

Returns the app with the given address. If the requested app account does not exist then and empty account is returned. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getBrand('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(brand => { if(brand.active) { console.log(brand); //... other stuff } }) // or with the async syntax async function foo() { let brand = await deveryRegistryClient.getBrand('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); if(brand.active) { console.log(brand); //... other stuff } } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a Brand you can click here to check its fields

Parameters:

Name Type Description brandAccount string address of the brand account

Returns the brand data for the given address. If the requested Brand account does not exist then and empty data is returned. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getBrandData('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(brandData => { console.log(brandData.appFeeAccount); //... other stuff }) // or with the async syntax async function foo() { let brandData = await deveryRegistryClient.getBrandData('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); console.log(brandData.appFeeAccount); //... other stuff } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a BrandData you can click here to check its fields

Parameters:

Name Type Description brandAccount string address of the brand account.

(async) brandAccountsArray (index) → {Promise.<string>}

Returns a brand account address from the brandAccounts array. If you try to access an index that is out of the array bounds the promise will be rejected. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.brandAccountsArray(4).then(address => { deveryClient.getBrand(address).then(brand => { console.log(brand.brandName); //... do more stuff }) }).catch(err => { console.log('index ot of bounds'); }) // or with the async syntax async function foo() { try { let accountAddress = await deveryRegistryClient.brandAccountsArray(4); let brand = await deveryRegistryClient.getBrand(accountAddress); console.log(brand.brandName); //... do more stuff } catch(err) { console.log('index ot of bounds'); } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description index int the account index inside the appAccounts array.

(async) brandAccountsLength () → {Promise.<int>}

Returns the total count of brand accounts registered on the smart contract. This method is particularly useful in conjunction with brandAccountsArray because you can verify the array upper bounds. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.brandAccountsLength().then(totalAccounts => { for(let i = 0;i< totalAccounts;i++) { deveryRegistryClient.brandAccountsArray(i).then(address => { deveryRegistryClient.getBrand(address).then(brand => { console.log(brand.brandName); //... do more stuff }) }) } }) // optionally you can use the async syntax if you prefer const totalAccounts = await deveryRegistryClient.brandAccountsLength(); for(let i = 0; i < totalAccounts; i++) { const address = await deveryRegistryClient.brandAccountsArray(i); const brand = await deveryRegistryClient.getBrand(address); console.log(brand.brandName); //... do more stuff } for more info about how to get a DeveryRegistry instance click here.

setBrandAddedEventListener (callback)

Listener to BrandAdded events. This event triggers whenever a new devery brand is added on blockchain. Please note that BrandAddedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a BrandAddedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it DeveryRegistryClient.setBrandAddedEventListener((brandAccount,appAccount,active) => { // whenever a brand added we will log it to the console console.log(`new brand has been added ${brandAccount} - ${appAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter DeveryRegistryClient.setBrandAddedEventListener(undefined); // or that is equivalent to the above call DeveryRegistryClient.setBrandAddedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback BrandEventCallback the callback that will be executed whenever and BrandAdded event is triggered

Listener to BrandUpdated events. This event triggers whenever an existing brand is updated in the blockchain. Please note that BrandUpdatedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a BrandUpdatedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it deveryRegistryClient.setBrandUpdatedEventListener((brandAccount,appAccount,active) => { // whenever a brand updated we will log it to the console console.log(`a brand has been updated ${brandAccount} - ${appAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter deveryRegistryClient.setBrandUpdatedEventListener(undefined); // or that is equivalent to the above call deveryRegistryClient.setBrandUpdatedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback BrandEventCallback the callback that will be executed whenever a BrandUpdated event is triggered

(async) addProduct (productAccount, description, details, year, origin, overrideOptions opt ) → {Promise.<Transaction>}

Creates a new Product in the blockchain. This is a write method, so you will need to provide some gas to run it. Plus keep in mind that your environment needs to have access to a signer, so make sure that you user have access to Metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.addProduct('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product','batch 001',2018,'Unknown place').then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.addProduct('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product','batch 001',2018,'Unknown place'); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description productAccount string product account address description string your product name and description details string any extra details about your product year int product's year of production origin string information about the product origin overrideOptions TransactionOptions <optional>

gas options to override the default ones

Updates an existing Product in the blockchain. This is a write method, so you will need to provide some gas to run it. Plus keep in mind that your environment needs to have access to a signer, so make sure that your user have access to Metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.updateProduct('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product' ,'batch 001',2018,'Unknown place',true).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.updateProduct('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product' ,'batch 001',2018,'Unknown place',true); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description productAccount string product account address description string your product name and description details string any extra details about your product year int product's year of production origin string information about the product origin active boolean enables or disable the product overrideOptions TransactionOptions <optional>

gas options to override the default ones

Returns the Product with the given address. If the requested Product account does not exist then you will receive an object with default data. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getProduct('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(product => { if(product.active) { console.log(product.details); //... other stuff } }) // or with the async syntax async function foo() { let product = await deveryRegistryClient.getProduct('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); if(product.active) { console.log(product.details); //... other stuff } } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a Product you can click here to check its fields

Parameters:

Name Type Description productAccount string address of the product account.

Returns the Product data for the given address. If the requested Product account does not exist then and empty data is returned. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.getProductData('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732').then(productData => { console.log(productData.brandAccount); //... other stuff }) // or with the async syntax async function foo() { let productData = await deveryRegistryClient.getProductData('0xf17f52151EbEF6C7334FAD080c5704DAAA16b732'); console.log(productData.brandAccount); //... other stuff } for more info about how to get a DeveryRegistry instance click here. The returned promise if resolved will return a ProductData you can click here to check its fields

Parameters:

Name Type Description productAccount string address of the product account.

(async) productAccountsPaginated (page, pagesize) → {Promise.<Array.<string>>}

Returns an array of product addresses from the productAccounts array contained in the smart contract. If you try to access a page that does not exist you will get a promise that resolves to an empty array as result. The parameters page and pagesize are optional. // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.productAccountsPaginated(0,20).then(addressArr => { for(let address of addressArr) { console.log(address); } }) // or with the async syntax async function foo() { // here we don't pass any param to productAccountsPaginated // because its parameters are optional let addressArr = await deveryRegistryClient.productAccountsPaginated(); for(let address of addressArr) { console.log(address); } //... do more stuff } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Default Description page int 0 the requested page. This parameter is optional, the default value to it is 0. pagesize int 10 the requested page size. This parameter is optional, the default value to it is 10.

(async) productAccountsArray (index) → {Promise.<string>}

Returns a Product account address from the productAccounts array. If you try to access an index that is out of the array bounds the promise will be rejected. // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.productAccountsArray(4).then(address => { deveryClient.getProduct(address).then(product => { console.log(product.productDescription); //... do more stuff }) }).catch(err => { console.log('index ot of bounds'); }) // or with the async syntax async function foo() { try { let productAddress = await deveryRegistryClient.productAccountsArray(4); let product = await deveryRegistryClient.getProduct(productAddress); console.log(product.productDescription); //... do more stuff } catch(err) { console.log('index ot of bounds'); } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description index int the account index inside the productAccounts array.

(async) productAccountsLength () → {Promise.<int>}

Returns the total count of product accounts registered on the smart contract. This method is particularly useful to be used in conjunction with productAccountsArray because you can verify the array upper bounds. // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.productAccountsLength().then(totalProducts => { for(let i = 0;i< totalProducts;i++) { deveryRegistryClient.productAccountsArray(i).then(address => { deveryRegistryClient.getProduct(address).then(product => { console.log(product.productDescription); //... do more stuff }) }) } }) // optionally you can use the async syntax if you prefer const totalProducts = await deveryRegistryClient.productAccountsLength(); for(let i = 0; i < totalProducts; i++) { const address = await deveryRegistryClient.productAccountsArray(i); const product = await deveryRegistryClient.getProduct(address); console.log(product.productDescription); //... do more stuff } for more info about how to get a DeveryRegistry instance click here.

setProductAddedEventListener (callback)

Listener to productAdded events. This event triggers whenever a new product is created in the blockchain. Please note that ProductAddedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a ProductAddedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it deveryRegistryClient.setProductAddedEventListener((productAccount,brandAccount,appAccount,description,active) => { // whenever a product created we will log it to the console console.log(`a product has been added ${productAccount} - ${brandAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter deveryRegistryClient.setProductAddedEventListener(undefined); // or that is equivalent to the above call deveryRegistryClient.setProductAddedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback ProductEventCallback the callback that will be executed whenever a ProductAdded event is triggered

Listener to productUpdated events. This event triggers whenever a product is updated in the blockchain. Please note that ProductUpdatedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a ProductUpdatedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it deveryRegistryClient.setProductUpdatedEventListener((productAccount,brandAccount,appAccount,description,active) => { //whenever a product updated we will log it to the console console.log(`a product has been updated ${productAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter deveryRegistryClient.setProductUpdatedEventListener(undefined); // or that is equivalent to the above call deveryRegistryClient.setProductUpdatedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback ProductEventCallback the callback that will be executed whenever a ProductUpdated event is triggered

(async) permissionMarker (marker, permission, overrideOptions opt ) → {Promise.<Transaction>}

Adds or removes permission from an account to mark items in the blockchain. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // passing true as param will add the account as marker deveryRegistryClient.permissionMarker('0x627306090abaB3A6e1400e9345bC60c78a8BEf57',true).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { // passing false as param will remove the account as marker let transaction = await deveryRegistryClient.permissionMarker('0x627306090abaB3A6e1400e9345bC60c78a8BEf57',false); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description marker string The marker account whose permission will be set permission boolean add or remove permission flag overrideOptions TransactionOptions <optional>

transaction gas options to override.

(async) addressHash (item) → {Promise.<Transaction>}

Compute item hash from the public key. You will need this hash to mark your products. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.addressHash('0x627306090abaB3A6e1400e9345bC60c78a8BEf57').then(hash => { // use the hash to mark the item //... other stuff }) for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description item string address to compute hash.

(async) mark (productAccount, itemHash, overrideOptions opt ) → {Promise.<Transaction>}

Marks an item in the blockchain. you need to pre calculate the item hash before calling this method Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); const address = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57' deveryRegistryClient.addressHash(address).then(hash => { deveryRegistryClient.mark(address,hash).then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here } }) // or with the async syntax async function foo() { try { const address = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57'; const hash = await deveryRegistryClient.addressHash(address); let transaction = await deveryRegistryClient.mark(address,hash); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')){ console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description productAccount string product account address. itemHash string item hash overrideOptions TransactionOptions <optional>

gas options to override the default ones

(async) AddProductAndMark (productAccount, description, details, year, origin, overrideOptions opt ) → {Promise.<Transaction>}

Creates a new Product in the blockchain and automatically mark it. Calling addProduct and mark separately will have the same result, this is just a wrapper that does both calls on your behalf, that means that once you call this method you will see 2 transactions (1 for add product and 1 for mark). This is a write method so you will need to provide some gas to run it, plus keep in mind that your environment need to have access to an signer so make sure that your user have access to metamask or other web3 object. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.AddProductAndMark('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product','batch 001',2018,'Unknown place').then(transaction => { console.log('transaction address',transaction.hash); //... other stuff }).catch(err => { if(err.message.indexOf('User denied')) { console.log('The user denied the transaction'); //... } // handle other exceptions here }) // or with the async syntax async function foo() { try { let transaction = await deveryRegistryClient.AddProductAndMark('0x627306090abaB3A6e1400e9345bC60c78a8BEf57','My nice product','batch 001',2018,'Unknown place'); console.log('transaction address',transaction.hash); } catch(err) { if(err.message.indexOf('User denied')){ console.log('The user denied the transaction'); //... } // handle other exceptions here } } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Attributes Description productAccount string product account address description string your product name and description details string any extra details about your product year int year of the product production origin string information about the product origin overrideOptions TransactionOptions <optional>

gas options to override the default ones

(async) hashAndMark (productAccount, overrideOptions) → {Promise.<Transaction>}

Parameters:

Name Type Description productAccount overrideOptions

Check if a given marked item exists in the blockchain and returns a MarkResult containing information about the product. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); deveryRegistryClient.check('0x627306090abaB3A6e1400e9345bC60c78a8BEf57').then(item => { console.log('product brand',item.brandAccount); //... other stuff }) // or with the async syntax async function foo() { let item = await deveryRegistryClient.check('0x627306090abaB3A6e1400e9345bC60c78a8BEf57'); console.log('product brand',item.brandAccount); } for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description item string The product account address in the blockchain to check.

setPermissionedEventListener (callback)

Listener to Permissioned events. This event triggers whenever a new permission is set in the blockchain. Please note that PermissionedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a PermissionedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it deveryRegistryClient.setPermissionedEventListener((marker,brandAccount,permission) => { console.log(`a brand has been updated ${brandAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter deveryRegistryClient.setPermissionedEventListener(undefined); // or that is equivalent to the above call deveryRegistryClient.setPermissionedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback PermissionedEventCallback the callback that will be executed whenever a Permissioned event is triggered

setMarkedEventListener (callback)

Listener to Marked events. This event triggers whenever a new account is marked in the blockchain. Please note that MarkedEventListeners do not stack, this means that whenever you set one you are removing the last one. If you want to remove a MarkedEventListener, just call this function passing undefined as param. Usage example: // first you need to get a DeveryRegistry instance let deveryRegistryClient = new DeveryRegistry(); // now you can use it deveryRegistryClient.setMarkedEventListener((brandAccount,appAccount,active) => { console.log(`a brand has been updated ${brandAccount} - ${appAccount} ...`); }) // if you want to remove the listener you can simply pass undefined as parameter deveryRegistryClient.setMarkedEventListener(undefined); // or that is equivalent to the above call deveryRegistryClient.setMarkedEventListener(); for more info about how to get a DeveryRegistry instance click here.

Parameters:

Name Type Description callback MarkedEventCallback the callback that will be executed whenever a Marked event is triggered

getSignerAddress () → {*}

You can use this method to check the current signer wallet address.

getProvider () → {*}