Query a single attribute
Use the getAttributes()
function from the QuadReader smart contract to query a single attribute about a passport holder.
Requirements
Installation
Install @quadrata/contracts package
npm i @quadrata/contracts --save-dev
Permissions
Calling smart contract have to be granted permissions to call getAttributes
in Mainnet.
Contact us via email at contact@quadrata.com or Discord
Function
import "@quadrata/contracts/interfaces/IQuadPassportStore.sol";
// For Solidity version >= 0.8.0.
reader.getAttributes(
address user,
bytes32 attribute
) external payable returns(
IQuadPassportStore.Attribute[] memory attributes
);
// For Solidity version < 0.8.0.
reader.getAttributesLegacy(
address user,
bytes32 attribute
) external payable returns(
bytes32[] attributeValues,
uint256[] epochs,
address[] issuers
);
Parameters
Parameter
Description
Type
user
address of the passport holder
address (required)
attribute
bytes32 (required)
Return values
A list of attributes that have been issued.
/// @dev Attribute store infomation as it relates to a single attribute
/// `attrKeys` Array of keys defined by (wallet address/DID + data Type)
/// `value` Attribute value
/// `epoch` timestamp when the attribute has been verified by an Issuer
/// `issuer` address of the issuer issuing the attribute
struct Attribute {
bytes32 value;
uint256 epoch;
address issuer;
}
Example
You can find our helper library to facilitate parsing the response => QuadReaderUtils
import "@quadrata/contracts/interfaces/IQuadReader.sol";
import "@quadrata/contracts/interfaces/IQuadPassportStore.sol";
import "@quadrata/contracts/utility/QuadReaderUtils.sol";
contract MyDapp {
using QuadReaderUtils for bytes32;
IQuadReader public reader;
function borrowMoney() external payable {
IQuadPassportStore.Attribute[] memory attributes = reader.getAttributes(
msg.sender,
keccak256("COUNTRY")
);
require(attributes.length > 0, "REQUIRES_COUNTRY");
// only users residing outside the US may borrow money
if (!attributes[0].value.countryIsEqual("US")) {
// Allow borrow actions
}
}
Last updated