Solidity Smart contracts for Issuers and Holders.
We are using truffle and ganache-cli for our smart contract development
Install testrpc and truffle
$ npm install -g testrpc
$ npm install -g ganache-cli
Install project dependencies
$ npm install
Start your Ethereum ganache node you might have to alter gas limit, we have seem differences on different OS
$ ganache-cli -l 4500000000000 --network-id 3000 --port 8000
Next cd into badgeforce cloned directory and run test, make sure dependencies are installed
$ ganache-cli test
Usage examples are in JavaScript using web3 and truffle
Issuer.sol
The Issuer smart contract acts as a representation of an issuer entity in the real world such as a univeristy or organization. You can authorized many issuers on one Issuer contract, i.e: authorizing all the deans of the math department on the Math departments Issuer contract. This way they can all issue credentials. As these contracts are further developed we will be able to represent organizations more flexibly such as chaining together Issuer contracts to make up an organization, and we will extend the capabilities of badges such as data, and relation to one another (micro badges representing courses taken within a certain program).
Automatic getter function generated for admin property on Issuer smart contract. Admin acts as God account and has special access to methods.
adminAddress
const adminAddress = await issuer.admin();
Function returns info for a authorized account
address
- the address of the authorized issuer account you want to retrieve
AuthorizedAccount
const authorizedAccountData = await issuer.authorizedAccountsMap(0x0000);
const authorizedAccountData = await issuer.getAuthorizedAccount(0x0000);
Function sets new authorized account. Use this function to add any enable new ethereum wallets to issue from your Issuer smart contract.
address
- the address of the issuer account you want to authorize
await issuer.authorzeAccount(0x0000);
Function removes an authorized account. Once an account is unauthorized the issuer that ethereum account belongs to will no longer be able to call methods with authorized modifier
address
- the address of the authorized issuer account you want to unauthorize
await issuer.removeAuthorizedAccount(0x0000);
Function gets the number of authorized accounts. A UI client or API interacting with an Issuer smart contract can use this function in conjunction with the getAuthorizedAccount method to retrieve all accounts authorized on the contract
const count = await issuer.getNumberOfAuthorizedAccounts();
Function returns information about the issuer and smart contract
address
- the admin address on this contractaddress
- the address of the issuer contract it's selfstring
- name of the issuerstring
- url associated with the issuer
const info = await issuer.getInfo();
Function is used to create a new badge. This method will be extended to hold more data and more types of badges as the BadgeLibrary is further developed.
string
- description of the badgestring
- name of the badgestring
- image urlstring
- badge versionstring
- json
const createBadgeParams = {
_description: "This badge is super cool",
_name: "Cool badge",
_image: "http://some/image/url",
_version: "1",
_json: "json"
}
await issuer.createBadge(...Object.values(createBadgeParams));
Function is used to delete a badge.
string
- name of the badge to delete
await issuer.deleteBadge(name);
Function is used to get the number of badges. A UI client or API interacting with an Issuer smart contract can use this function in conjunction with the getBadge method to retrieve all badges
const count = await issuer.getNumberOfBadges();
Function is used to get a badge.
uint
- badge index
const badge = await issuer.getBadge(index);
Function is used to issue a credential to a holder contract.
string
- name of a badge that already exists on the issuer smart contractaddress
- address of the holder contract to issue credential touint
- unix timstamp for expiration date or 0 for non expiring
const issueParams = {
_badgeName: "Fresh New Badge",
_recipient: 0x0,
_expires: 0,
}
await issuer.issue(...Object.values(issueParams));
Function is used to revoke a badge. Once a credential is revoked it will fail verification.
bytes32
- transaction key of the credential to revoke
await issuer.revoke(credential._txKey);
Function is used to un-revoke a credential. Can be used if a credential is revoked on error.
bytes32
- transaction key of the credential to revoke
await issuer.unRevoke(credential._txKey);
Function is used to check if a credential is revoked.
bytes32
- transaction key of the credential to check
const check = await issuer.isRevoked(redential._txKey);
Holder.sol
The Holder smart contract represents a holder or recipient of credentials, badges and certifications in the real world. This is where a holder will be able access all their earned credentials, and consumers will be able to query these contracts for credential verification. A Holder smart contract is owned by the holder in the real world by attaching it to an ethereum wallet address that they own.
Function is used to get the number of credentials on the Holder contract. This can be used in conjunction with the getCredential function to get all the holders credentials.
const count = await holder.getNumberOfCredentials();
Function to retrieve a credential by it's index.
uint
- index of the credential
const check = await holder.getCredential(index);
Function is verify a credential.
bytes32
- index of the credential
bool
- true or false if the credential is verifiedmessage
- success or failure message
const check = await holder.verifyCredential(index);