DeveryRegistry

DeveryRegistry

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.

DeveryRegistry Smart Contract Design:

# Devery Protocol Contracts


Mainnet Address: 0x0364a98148b7031451e79b93449b20090d79702a

## DeveryRegistry Smart Contract Design ##
mapping(appAccount => App[address appAccount, string appName, address feeAccount, uint fee, bool active]) apps`
mapping(brandAccount => Brand[address brandAccount, address appAccount, string brandName, bool active]) brands`
mapping(productAccount => Product[address productAccount, address brandAccount, string description, string details, uint year, string origin, bool active]) products`
mapping(sha3(itemPublicKey) => productAccount) markings`
mapping(markerAccount => (brandAccount => permission)) permissions`


## Functions

## App Accounts

An account can add itself as an ***App*** account using `addApp(string appName, address feeAccount)`
An account can update it's ***App*** account data using `updateApp(string appName, address feeAccount, bool active)`



### Brand Accounts

An ***App*** account can add ***Brand*** accounts using `addBrand(address brandAccount, string brandName)`
An ***App*** account can update it's ***Brand*** account data using `updateBrand(address brandAccount, string brandName, bool active)`



### Product Accounts

A ***Brand*** account can add ***Product*** accounts using `addProduct(address productAccount, string description, string details, uint year, string origin)`
A ***Brand*** account can update it's ***Product*** account data using `updateProduct(address productAccount, string description, string details, uint year, string origin, bool active)`



### Permissions

A ***Brand*** account can add ***Marker*** accounts using `permissionMarker(address marker, bool permission)`



### Marking

A ***Marker*** account can add the hash of an ***Item***'s public key using `mark(address productAccount, bytes32 itemHash)`. The `productAccount` is the
type of ***Product*** the ***Item*** is.



## Checking

Anyone can check the validity of an ***Item***'s public key using `check(address item)`


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:

Extends

Methods

(async) estimateAddBrand(brandAccount, brandName, overrideOptions)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.addBrand the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.addBrand. the return of this method will be the total gas used to call DeveryRegistry.addBrand with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.addBrand would be a valid call

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

Source:

(async) addApp(appName, feeAccount, fee, overrideOptionsopt) → {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

Source:

(async) estimateAddApp(appName, feeAccount, fee, overrideOptionsopt)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.addApp the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.addApp. the return of this method will be the total gas used to call DeveryRegistry.addApp with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.addApp would be a valid call

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

Source:

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

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

Source:

(async) estimateUpdateApp(appName, feeAccount, fee, active, overrideOptions)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.updateApp the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.updateApp. the return of this method will be the total gas used to call DeveryRegistry.updateApp with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.updateApp would be a valid call

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

Source:

(async) getApp(appAccount) → {Promise.<App>}

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

Source:

(async) getAppData(appAccount) → {Promise.<AppData>}

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

Source:

(async) appAccountsPaginated(pageopt, pagesizeopt) → {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.

Source:

(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

Source:

(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.

Source:

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

Source:

setAppUpdatedEventListener(callback)

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

Source:

(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

Source:

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

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

Source:

(async) estimateUpdateBrand(brandAccount, brandName, active, overrideOptions)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.updateBrand the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.updateBrand. the return of this method will be the total gas used to call DeveryRegistry.updateBrand with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.updateBrand would be a valid call

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

Source:

(async) getBrand(brandAccount) → {Promise.<Brand>}

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

Source:

(async) getBrandData(brandAccount) → {Promise.<BrandData>}

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.

Source:

(async) brandAccountsPaginated(pageopt, pagesizeopt) → {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.

Source:

(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.

Source:

(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.

Source:

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

Source:

setBrandUpdatedEventListener(callback)

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

Source:

(async) addProduct(productAccount, description, details, year, origin, overrideOptionsopt) → {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

Source:

(async) estimateAddProduct(productAccount, description, details, year, origin, overrideOptionsopt)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.addProduct the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.addProduct. the return of this method will be the total gas used to call DeveryRegistry.addProduct with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.addProduct would be a valid call

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

Source:

(async) updateProduct(productAccount, description, details, year, origin, active, overrideOptionsopt) → {Promise.<Transaction>}

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

Source:

(async) estimateUpdateProduct(productAccount, description, details, year, origin, active, overrideOptionsopt)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.updateProduct the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.updateProduct. the return of this method will be the total gas used to call DeveryRegistry.updateProduct with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.updateProduct would be a valid call

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

Source:

(async) getProduct(productAccount) → {Promise.<Product>}

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.

Source:

(async) getProductData(productAccount) → {Promise.<ProductData>}

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.

Source:

(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.

Source:

(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.

Source:

(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.

Source:

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

Source:

setProductUpdatedEventListener(callback)

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

Source:

(async) permissionMarker(marker, permission, overrideOptionsopt) → {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.

Source:

(async) estimatePermissionMarker(marker, permission, overrideOptionsopt)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.permissionMarker the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.permissionMarker. the return of this method will be the total gas used to call DeveryRegistry.permissionMarker with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.permissionMarker would be a valid call

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.

Source:

(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.

Source:

(async) mark(productAccount, itemHash, overrideOptionsopt) → {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

Source:

(async) estimateMark(productAccount, itemHash, overrideOptionsopt)

This method gives an estimation of how much gas will be used for the method DeveryRegistry.mark the params that you pass to this method shall be exactly the same ones that you would pass to DeveryRegistry.mark. the return of this method will be the total gas used to call DeveryRegistry.mark with the given parameters. It's important to note that a call to this method will only be successful if the call to DeveryRegistry.mark would be a valid call

Parameters:
Name Type Attributes Description
productAccount string

product account address.

itemHash string

item hash

overrideOptions TransactionOptions <optional>

gas options to override the default ones

Source:

(async) AddProductAndMark(productAccount, description, details, year, origin, overrideOptionsopt) → {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

Source:

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

Parameters:
Name Type Description
productAccount
overrideOptions
Source:

(async) check(item) → {Promise.<MarkResult>}

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.

Source:

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

Source:

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

Source:

getSignerAddress() → {*}

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

Overrides:
Source:

getProvider() → {*}

Returns the internal signer or provider, this method needs to be used with caution as it exposes internals. So unless you know what you are doing it's better to avoid using it.

Overrides:
Source: