ERC725
decodeData
erc725.decodeData(data [, schemas]);
ERC725.decodeData(data, schemas);
If you are reading the key-value store from an ERC725 smart-contract you can use the decodeData
function to do the decoding for you.
tip
If you want total convenience, it is recommended to use the fetchData
function, which automatically decodes
and fetches
external references.
Parameters
1. data
- Object or array of Objects
An object or array of objects containing the following properties:
Name | Type | Description |
---|---|---|
keyName | string | Can be either the named key (i.e. LSP3Profile , LSP12IssuedAssetsMap:<address> ) or the hashed key (with or without 0x prefix, i.e. 0x5ef... or 5ef... ). |
dynamicKeyParts (optional) | string or string[ ] | If keyName is a dynamic key, the dynamic parts of the keyName that will be used for encoding the key. |
value | string or string[ ] | The value that should be decoded. Can be a string, an array of string or a JSON... |
The keyName
also supports dynamic keys for Mapping
and MappingWithGrouping
. Therefore, you can use variables in the key name such as LSP12IssuedAssetsMap:<address>
. In that case, the value should also set the dynamicKeyParts
property:
dynamicKeyParts
: string or string[ ] which holds the variables that needs to be encoded.
2. schemas
- Array of Objects (optional)
An array of extra LSP-2 ERC725YJSONSchema objects that can be used to find the schema. If called on an instance, it is optional and it will be concatenated with the schema provided on instantiation.
Returns
Name | Type | Description |
---|---|---|
decodedData | Object or Array | The decoded data as defined and expected in the following schemas. |
info
- If the input is an array of objects, the values will be returned in an array.
- If the input is a single object, the output will be the decodedData object directly.
Single-Key Example
erc725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
]);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
]
*/
erc725.decodeData({
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
});
/**
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
}
*/
Multi-Key Example
erc725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'LSP12IssuedAssets[]',
value: [
{
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
value:
'0x0000000000000000000000000000000000000000000000000000000000000002',
},
{
key: '0x7c8c3416d6cda87cd42c71ea1843df2800000000000000000000000000000000',
value: '0xd94353d9b005b3c0a9da169b768a31c57844e490',
},
{
key: '0x7c8c3416d6cda87cd42c71ea1843df2800000000000000000000000000000001',
value: '0xdaea594e385fc724449e3118b2db7e86dfba1826',
},
],
},
]);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
hashFunction: 'keccak256(utf8)',
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
{
name: 'LSP12IssuedAssets[]',
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
value: [
'0xD94353D9B005B3c0A9Da169b768a31C57844e490',
'0xDaea594E385Fc724449E3118B2Db7E86dFBa1826',
],
},
];
*/
Dynamic-Key Example
const schemas = [
{
name: 'MyKeyName:<bytes32>:<bool>',
key: '0x...',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'JSONURL',
},
];
erc725.decodeData(
[
{
keyName: 'MyKeyName:<bytes32>:<bool>',
dynamicKeyParts: [
'0xaaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa',
'true',
],
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
],
schemas,
);
/**
[
{
name: 'MyKeyName:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
key: '0x35e6950bc8d2aaaabbbb00000000000000000000000000000000000000000001',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
];
*/
decodePermissions
ERC725.decodePermissions(permission);
Decodes permissions from hexadecimal defined by the LSP6 KeyManager Standard.
info
decodePermissions
is available as either a static or non-static method so can be called without instantiating an ERC725 object.
Parameters
1. permission
- String
The encoded permission (32bytes hex).
Returns
Name | Type | Description |
---|---|---|
decodedPermissions | Object | An object specifying whether default LSP6 permissions are included in provided hexademical string. |
Example
ERC725.decodePermissions('0x0000000000000000000000000000000000000000000000000000000000000110'),
/**
{
CHANGEOWNER: false,
CHANGEPERMISSIONS: false,
ADDPERMISSIONS: false,
SETDATA: false,
CALL: true,
STATICCALL: false,
DELEGATECALL: false,
DEPLOY: false,
TRANSFERVALUE: true,
SIGN: false,
}
*/
ERC725.decodePermissions('0x000000000000000000000000000000000000000000000000000000000000000a'),
/**
{
CHANGEOWNER: false,
CHANGEPERMISSIONS: true,
ADDPERMISSIONS: false,
SETDATA: true,
CALL: false,
STATICCALL: false,
DELEGATECALL: false,
DEPLOY: false,
TRANSFERVALUE: false,
SIGN: false,
}
*/
// This method is also available on the instance:
myErc725.decodePermissions('0x0000000000000000000000000000000000000000000000000000000000000110'),
encodeData
erc725.encodeData(data [, schemas]);
ERC725.encodeData(data, schemas);
Encode the data of a smart contract according to your ERC725JSONSchema
so that you can store the information in smart contracts.
tip
When encoding JSON, it is possible to pass in the JSON object and the URL where it is available publicly. The JSON will be hashed with keccak256
.
Parameters
1. data
- Object or array of Objects
An object or array of objects containing the following properties:
Name | Type | Description |
---|---|---|
keyName | string | Can be either the named key (i.e. LSP3Profile , LSP12IssuedAssetsMap:<address> ) or the hashed key (with or without 0x prefix, i.e. 0x5ef... or 5ef... ). |
dynamicKeyParts (optional) | string or string[ ] | The dynamic parts of the keyName that will be used for encoding the key. |
value | string or string[ ] JSON todo | The value that should be encoded. Can be a string, an array of string or a JSON... |
The keyName
also supports dynamic keys for Mapping
and MappingWithGrouping
. Therefore, you can use variables in the key name such as LSP12IssuedAssetsMap:<address>
. In that case, the value should also set the dynamicKeyParts
property:
dynamicKeyParts
: string or string[ ] which holds the variables that needs to be encoded.
2. schemas
- Array of Objects (optional)
An array of extra LSP-2 ERC725YJSONSchema objects that can be used to find the schema. If called on an instance, it is optional and it will be concatenated with the schema provided on instantiation.
Returns
Name | Type | Description |
---|---|---|
encodedData | Object | An object containing the encoded keys and values according to the LSP2 ERC725Y JSON Schema of the data which was passed |
After the data
is encoded, the object is ready to be stored in smart contracts.
Examples
erc725.encodeData([
{
keyName: 'LSP3Profile',
value: {
json: profileJson,
url: 'ipfs://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
},
},
]);
/**
{
keys: ['0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
values: ['0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d'],
}
*/
// You can also use the hashed key (with or without 0x prefix)
erc725.encodeData([
{
keyName:
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
json: profileJson,
url: 'ipfs://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
},
},
]);
/**
{
keys: ['0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
values: ['0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d'],
}
*/
erc725.encodeData([
{
keyName: '5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
json: profileJson,
url: 'ipfs://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
},
},
]);
/**
{
keys: ['0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
values: ['0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d'],
}
*/
erc725.encodeData({
keyName: 'LSP1UniversalReceiverDelegate',
value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb',
});
/**
{
keys: ['0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47'],
values: ['0x1183790f29be3cdfd0a102862fea1a4a30b3adab'],
}
*/
erc725.encodeData([
{
keyName: 'LSP3Profile',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
]);
/**
{
keys: ['0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
values: ['0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178'],
}
*/
const schemas = [
{
name: 'DynamicKey:<address>',
key: '0x0fb367364e1852abc5f20000<address>',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'Address',
},
];
erc725.encodeData(
[
{
keyName: 'DynamicKey:<address>',
dynamicKeyParts: ['0xbedbedbedbedbedbedbedbedbedbedbedbedbedb'],
value: '0xcafecafecafecafecafecafecafecafecafecafe',
},
],
schemas,
);
/**
{
keys: ['0x0fb367364e1852abc5f20000bedbedbedbedbedbedbedbedbedbedbedbedbedb'],
values: ['0xcafecafecafecafecafecafecafecafecafecafe]
}
*/
const schemas = [
{
name: 'DynamicKey:<bytes4>:<string>',
key: '0xForDynamicKeysThisFieldIsIrrelevantAndWillBeOverwriten',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'Address',
},
];
erc725.encodeData(
[
{
keyName: 'DynamicKey:<bytes4>:<string>',
dynamicKeyParts: ['0x11223344', 'Summer'],
value: '0xcafecafecafecafecafecafecafecafecafecafe',
},
],
schemas,
);
/**
{
keys: ['0x0fb367364e1852abc5f2000078c964cd805233eb39f2db152340079088809725'],
values: ['0xcafecafecafecafecafecafecafecafecafecafe']
}
*/
erc725.encodeData([
{
keyName: 'LSP3Profile',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
{
keyName: 'LSP12IssuedAssets[]',
value: [
'0xD94353D9B005B3c0A9Da169b768a31C57844e490',
'0xDaea594E385Fc724449E3118B2Db7E86dFBa1826',
],
},
{
keyName: 'LSP1UniversalReceiverDelegate',
value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb',
},
]);
/**
{
keys: [
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
'0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
'0x7c8c3416d6cda87cd42c71ea1843df2800000000000000000000000000000000',
'0x7c8c3416d6cda87cd42c71ea1843df2800000000000000000000000000000001',
'0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
],
values: [
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x0000000000000000000000000000000000000000000000000000000000000002',
'0xd94353d9b005b3c0a9da169b768a31c57844e490',
'0xdaea594e385fc724449e3118b2db7e86dfba1826',
'0x1183790f29be3cdfd0a102862fea1a4a30b3adab',
],
}
*/
encodeKeyName
ERC725.encodeKeyName(keyName [, dynamicKeyParts]);
Hashes a key name for use on an ERC725Y contract according to the LSP2 ERC725Y JSON Schema Standard.
info
encodeKeyName
is available as either a static or non-static method so can be called without instantiating an ERC725 object.
Parameters
1. keyName
- String
The key name you want to encode, for instance: LSP3Profile
.
2. dynamicKeyParts
- String or array of Strings (optional)
The variables used to encode the key name, if the key name is a dynamic (i.e.: MyKey:<address>
...)
Returns
Name | Type | Description |
---|---|---|
encodedKeyName | string | The keccak256 hash of the provided key name. |
The hash must be retrievable from the ERC725Y contract via the getData function.
Example
ERC725.encodeKeyName('LSP3Profile');
// '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'
ERC725.encodeKeyName('SupportedStandards:LSP3UniversalProfile');
// '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38'
ERC725.encodeKeyName(
'AddressPermissions:Permissions:cafecafecafecafecafecafecafecafecafecafe',
);
// '0x4b80742de2bf82acb3630000cafecafecafecafecafecafecafecafecafecafe'
ERC725.encodeKeyName('MyKeyName:<bool>', 'true');
// '0x35e6950bc8d21a1699e500000000000000000000000000000000000000000001'
ERC725.encodeKeyName('MyKeyName:<bytes2>:<uint32>', ['ffff', '4081242941']);
// 0x35e6950bc8d20000ffff000000000000000000000000000000000000f342d33d
ERC725.encodeKeyName('MyKeyName:<uint32>', ['4081242941']);
// 0x35e6950bc8d21a1699e5000000000000000000000000000000000000f342d33d
// This method is also available on the instance:
myErc725.encodeKeyName('LSP3Profile');
encodePermissions
ERC725.encodePermissions(permissions);
Encodes permissions into a hexadecimal string as defined by the LSP6 KeyManager Standard.
info
encodePermissions
is available as either a static or non-static method so can be called without instantiating an ERC725 object.
Parameters
1. permissions
- Object
An object with LSP6 KeyManager Permissions as keys and a boolean
as value. Any ommited permissions will default to false
.
Returns
Name | Type | Description |
---|---|---|
Promise | string | The permissions encoded as a hexadecimal string defined by the LSP6 KeyManager Standard |
Example
ERC725.encodePermissions({
CHANGEOWNER: false,
CHANGEPERMISSIONS: false,
ADDPERMISSIONS: false,
SETDATA: false,
CALL: true,
STATICCALL: false,
DELEGATECALL: false,
DEPLOY: false,
TRANSFERVALUE: true,
SIGN: false,
}),
// '0x0000000000000000000000000000000000000000000000000000000000000110'
// Any ommited Permissions will default to false
ERC725.encodePermissions({
CHANGEPERMISSIONS: true,
SETDATA: true,
}),
// '0x000000000000000000000000000000000000000000000000000000000000000a'
// This method is also available on the instance:
myErc725.encodePermissions({
CHANGEPERMISSIONS: true,
SETDATA: true,
}),
fetchData
erc725.fetchData([keys]);
The fetchData
function fetches smart contract data and can additionally return JSONURL
or ASSETURL
data from IPFS, HTTP, or HTTPS endpoints.
info
To ensure data authenticity fetchData
compares the hash
of the fetched JSON with the hash
stored on the blockchain.
info
If you get the ReferenceError: fetch is not defined
error, you need to install and import isomorphic-fetch
.
Parameters
1. keys
- String, Object or array of Strings or/and Objects (optional)
The name(s) (or the encoded name(s) as schema key) of the element(s) in the smart contract's schema. If no keys are set, it will fetch all the non dynamic schema keys given at instantiation. For dynamic keys, you can use the object below:
Name | Type | Description |
---|---|---|
keyName | string | The dynamic key name, such as MyKey:<address> |
dynamicKeyParts | string or string[ ] | The dynamic parts of the keyName that will be used for encoding the key. |
Returns
Name | Type | Description |
---|---|---|
data | Promise<Array> or Promise<Object> | An array with same objects as for decodeData() function but with the value being remplaced by the actual file for JSONURL and ASSETURL valueContent. If there is a hash mismatch, the value will be null . |
info
- If the input is an array, the values will be returned in an array.
- If the input is a single key, the output will be the object directly.
All-Keys Example
await erc725.fetchData();
/**
[
{
name: 'SupportedStandards:LSP3UniversalProfile',
key: '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38',
value: '0xabe425d6'
},
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: { LSP3Profile: [Object] }
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0xE2D6038acD92200790Df695Ebd13856CdF2a6942'
},
{
name: 'LSP12IssuedAssets[]',
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
value: [
'0xc444009d38d3046bb0cF81Fa2Cd295ce46A67C78',
'0x4fEbC3491230571F6e1829E46602e3b110215A2E',
'0xB92a8DdA288638491AEE5C2a003D4CAbfa47aE3F',
'0x1e52e7F1707dcda57dD33F003B2311652A465acA',
'0x0BDA71aA980D37Ea56E8a3784E4c309101DAf3E4',
'0xfDB4D9C299438B9839e9d04E34B9609C5b56600D',
'0x081D3F0bff8ae2339cb65113822eEc1510704d5c',
'0x55C98c6944B7497FaAf4db0386a1aD1E6efF526E',
'0x90D1a1D68fa23AEEE991220703f1a1C3782e0b35',
'0xdB5AB19792d9fB61c1Dff57810Fb7C6f839Af8ED'
]
}
]
*/
Single-Key Example
await erc725.fetchData('LSP3Profile');
/**
{
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
name: 'LSP3Profile',
value: { LSP3Profile: { name: 'Test', description: 'Cool' } }
}
*/
await erc725.fetchData(['LSP1UniversalReceiverDelegate']);
/**
[
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0xE2D6038acD92200790Df695Ebd13856CdF2a6942'
}
]
*/
Multi-Keys / Dynamic-Keys Example
await erc725.fetchData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: { LSP3Profile: [Object] }
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0xE2D6038acD92200790Df695Ebd13856CdF2a6942'
}
]
*/
await erc725.fetchData([
'LSP1UniversalReceiverDelegate',
{
keyName: 'LSP12IssuedAssetsMap:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
},
]);
/**
[
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0xE2D6038acD92200790Df695Ebd13856CdF2a6942'
},
{
name: 'LSP12IssuedAssetsMap:cafecafecafecafecafecafecafecafecafecafe',
key: '0x74ac2555c10b9349e78f0000cafecafecafecafecafecafecafecafecafecafe',
value: null
}
]
*/
getData
erc725.getData([keys]);
Gets decoded data for one, many, or all of the specified ERC725
smart contract's keys.
When omitting the keys
parameter, it will give back every key (as per ERC725JSONSchema
definition).
caution
Parameters
1. keys
- String, Object or array of Strings or/and Objects (optional)
The name(s) (or the encoded name(s) as schema key) of the element(s) in the smart contract's schema. If no keys are set, it will fetch all the non dynamic schema keys given at instantiation. For dynamic keys, you can use the object below:
Name | Type | Description |
---|---|---|
keyName | string | The dynamic key name, such as MyKey:<address> |
dynamicKeyParts | string or string[ ] | The dynamic parts of the keyName that will be used for encoding the key. |
Returns
Name | Type | Description |
---|---|---|
data | Promise<Array> or Promise<Object> | An array with same objects as for decodeData() function. |
info
- If the input is an array, the values will be returned in an array.
- If the input is a single key, the output will be the object directly.
All-Keys Example
await erc725.getData();
/**
[
{
name: 'SupportedStandards:LSP3UniversalProfile',
key: '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38',
value: '0xabe425d6',
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0x50A02EF693fF6961A7F9178d1e53CC8BbE1DaD68',
},
{
name: 'LSP12IssuedAssets[]',
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
value: [
'0xc444009d38d3046bb0cF81Fa2Cd295ce46A67C78',
'0x4fEbC3491230571F6e1829E46602e3b110215A2E',
'0xB92a8DdA288638491AEE5C2a003D4CAbfa47aE3F',
'0x1e52e7F1707dcda57dD33F003B2311652A465acA',
'0x0BDA71aA980D37Ea56E8a3784E4c309101DAf3E4',
'0xfDB4D9C299438B9839e9d04E34B9609C5b56600D',
'0x081D3F0bff8ae2339cb65113822eEc1510704d5c',
'0x55C98c6944B7497FaAf4db0386a1aD1E6efF526E',
'0x90D1a1D68fa23AEEE991220703f1a1C3782e0b35',
'0xdB5AB19792d9fB61c1Dff57810Fb7C6f839Af8ED'
],
},
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3',
url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5',
},
},
]
*/
Single-Key Example
await erc725.getData('LSP3Profile');
/**
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV'
},
}
*/
await erc725.getData(['LSP3Profile']);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV'
},
}
]
*/
await erc725.getData('LSP1UniversalReceiverDelegate');
/**
{
name: 'LSP1UniversalReceiverDelegate',
key: '0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0x50A02EF693fF6961A7F9178d1e53CC8BbE1DaD68',
}
*/
Multi-Key Example
await erc725.getData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p'
}
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
value: '0xE2D6038acD92200790Df695Ebd13856CdF2a6942'
}
]
*/
Dynamic-Key Example
await erc725.getData({
keyName: 'LSP12IssuedAssetsMap:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
});
/**
{
name: 'LSP12IssuedAssetsMap:cafecafecafecafecafecafecafecafecafecafe',
key: '0x74ac2555c10b9349e78f0000cafecafecafecafecafecafecafecafecafecafe',
value: '0x6b175474e89094c44da98b954eedeac495271d0f',
}
*/
await erc725.getData([
{
keyName: 'LSP12IssuedAssetsMap:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
},
]);
/**
[
{
name: 'LSP12IssuedAssetsMap:cafecafecafecafecafecafecafecafecafecafe',
key: '0x74ac2555c10b9349e78f0000cafecafecafecafecafecafecafecafecafecafe',
value: '0x6b175474e89094c44da98b954eedeac495271d0f',
}
]
*/
await erc725.getData([
'LSP3Profile',
{
keyName: 'LSP12IssuedAssetsMap:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
},
]);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p'
}
},
{
name: 'LSP12IssuedAssetsMap:cafecafecafecafecafecafecafecafecafecafe',
key: '0x74ac2555c10b9349e78f0000cafecafecafecafecafecafecafecafecafecafe',
value: null
}
]
*/
getOwner
erc725.getOwner([address]);
Returns the contract owner and is not directly related to ERC725 specifications.
Parameters
1. address
- String (optional)
The contract address you wish to find the owner of. If no address is set, will return the owner of the contract used to initialise the ERC725 class.
Returns
Name | Type | Description |
---|---|---|
Promise | string | The contract or EOA address of the owner. |
info
The address of the contract owner as stored in the contract.
Example
// If no address is set, it will return the owner of the contract used to initialise the ERC725() class.
await erc725.getOwner();
// '0x94933413384997F9402cc07a650e8A34d60F437A'
// You can also get the owner of a specific contract by setting the address parameter
await erc725.getOwner('0x3000783905Cc7170cCCe49a4112Deda952DDBe24');
// '0x7f1b797b2Ba023Da2482654b50724e92EB5a7091'
getSchema
erc725.getSchema(keys [, providedSchemas]);
Parses a hashed key or a list of hashed keys and will attempt to return its corresponding LSP2 ERC725YJSONSchema object. Additionally, it will look for a corresponding key within the schemas:
- in the
schemas
folder (which includes all LSPs), - that were provided at ERC725 initialisation, and
- that were provided in the function call (
providedSchemas
).
Parameters
1. keys
- String or array of Strings
The key(s) you are trying to get the schema for.
2. providedSchemas
- Object (optional)
An array of extra LSP-2 ERC725YJSONSchema objects that can be used to find the schema.
Returns
Name | Type | Description |
---|---|---|
result | ERC725JSONSchema | If the parameter keys is a string and the schema was found. |
result | Record string | If the parameter keys is a string[ ] and the schema was found. |
result | null | If the schema was not found. |
Example using a predefined LSP3 schema
erc725.getSchema(
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
);
/**
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueType: 'bytes'
}
*/
erc725.getSchema([
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
'0x3a47ab5bd3a594c3a8995f8fa58d087600000000000000000000000000000001',
]);
/**
{
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5': {
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueType: 'bytes'
},
'0x3a47ab5bd3a594c3a8995f8fa58d087600000000000000000000000000000001': {
name: 'LSP12IssuedAssets[1]',
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
keyType: 'Singleton',
valueContent: 'Address',
valueType: 'address'
}
}
*/
Example using a custom schema
erc725.getSchema(
'0x777f55baf2e0c9f73d3bb456dfb8dbf6e609bf557969e3184c17ff925b3c402c',
[
{
name: 'ParameterSchema',
key: '0x777f55baf2e0c9f73d3bb456dfb8dbf6e609bf557969e3184c17ff925b3c402c',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueType: 'bytes',
},
],
);
/**
{
name: 'ParameterSchema',
key: '0x777f55baf2e0c9f73d3bb456dfb8dbf6e609bf557969e3184c17ff925b3c402c',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueType: 'bytes',
}
*/
isValidSignature
erc725.isValidSignature(messageOrHash, signature);
Checks if a signature was signed by the owner
of the ERC725 Account contract, according to EIP-1271. If the owner
is a contract itself, it will delegate the isValidsignature()
call to the owner contract if it supports EIP-1271. Otherwise, it will fail.
Parameters
1. messageOrHash
- String
Value of a message or hash that needs to be verified.
2. signature
- String
The raw RLP encoded signature.
info
- The hash must be 66 chars long with the
0x
prefix, otherwise it will be interpreded as message. - The message will be: enveloped as
"\x19Ethereum Signed Message:\n" + message.length + message
and hashed usingkeccak256
function. The signature can be generated withweb3.eth.accounts.sign()
.
Returns
Name | Type | Description |
---|---|---|
Promise | boolean | true if signature is valid, false if signature is invalid. |
info
- A valid signature means that the smart contract response IS the MAGICVALUE:
0x1626ba7e
. - If this function is called on a contract which does not support EIP-1271, it will throw an error.
Examples
await erc725.isValidSignature(
'hello',
'0xb91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c',
);
// true
await erc725.isValidSignature(
'0x1da44b586eb0729ff70a73c326926f6ed5a25f5b056e7f47fbc6e58d86871655',
'0xcafecafeb915466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c',
);
// false