Skip to content

Commit

Permalink
Merge pull request #720 from lukso-network/tools-docs-sync
Browse files Browse the repository at this point in the history
Update Tools Documentation
  • Loading branch information
Hugoo authored Dec 11, 2023
2 parents b3e6f68 + 7c92f25 commit f0eacc1
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 99 deletions.
1 change: 1 addition & 0 deletions docs/learn/dapp-developer/transfer-lyx.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ await web3.eth.sendTransaction({
})
```
<!-- prettier-ignore-end -->

</TabItem>

<TabItem value="ethersjs" label="ethers.js">
Expand Down
317 changes: 235 additions & 82 deletions docs/tools/erc725js/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,67 @@ myErc725.decodePermissions('0x00000000000000000000000000000000000000000000000000

---

## decodeValueType

```js
myErc725.decodeValueType(type, data);
```

```js
ERC725.decodeValueType(type, data);
```

Decode some data according to a provided value type.

#### Parameters

| Name | Type | Description |
| :----- | :----- | :---------------------------------------------------------------------------- |
| `type` | string | The value type to decode the data (i.e. `uint256`, `bool`, `bytes4`, etc...). |
| `data` | string | A hex encoded string starting with `0x` to decode |

#### Returns

| Name | Type | Description |
| :------------- | :--------------------- | :----------------------------------- |
| `decodedValue` | string or <br/> number | A value decoded according to `type`. |

#### Examples

```javascript
myErc725.decodeValueType('uint128', '0x0000000000000000000000000000000a');
// 10

myErc725.decodeValueType('bool', '0x01');
// true

myErc725.decodeValueType('string', '0x48656c6c6f21');
// 'Hello!';

// also available for ABI encoded array + CompactBytesArray
myErc725.decodeValueType(
'uint256[]',
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001e',
);
// [ 10, 20, 30 ]

myErc725.decodeValueType(
'uint256[CompactBytesArray]'',
'0x0020000000000000000000000000000000000000000000000000000000000000000500200000000000000000000000000000000000000000000000000000000000000008'
)
// [ 5, 8 ]
```
This method is also available as a static method:
```js
ERC725.decodeValueType(
'uint256',
'0x000000000000000000000000000000000000000000000000000000000000002a',
);
// 42
```
## encodeData
```js
Expand Down Expand Up @@ -615,6 +676,178 @@ myErc725.encodeData([

</details>

<details>
<summary>Encode array length</summary>

If the key is of type Array and you pass an integer as a value (for instance, the array length), it will be encoded accordingly.

```javascript title="Encode the length of an array"
myErc725.encodeData([
{
keyName: 'LSP3IssuedAssets[]',
value: 5,
},
]);
/**
{
keys: [
'0x3a47ab5bd3a594c3a8995f8fa58d0876c96819ca4516bd76100c92462f2f9dc0',
],
values: ['0x00000000000000000000000000000005'],
}
*/
```

</details>

---

## encodePermissions

```js
ERC725.encodePermissions(permissions);
```

Encodes permissions into a hexadecimal string as defined by the [LSP6 KeyManager Standard](https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager).

:::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

| Type | Description |
| :----- | :---------------------------------------------------------------------------------------- |
| string | The permissions encoded as a hexadecimal string defined by the [LSP6 KeyManager Standard] |

#### Example

```javascript title="Encoding permissions"
ERC725.encodePermissions({
CHANGEOWNER: false,
ADDCONTROLLER: false,
EDITPERMISSIONS: false,
ADDEXTENSIONS: false,
CHANGEEXTENSIONS: true,
ADDUNIVERSALRECEIVERDELEGATE: false,
CHANGEUNIVERSALRECEIVERDELEGATE: false,
REENTRANCY: false,
SUPER_TRANSFERVALUE: true,
TRANSFERVALUE: true,
SUPER_CALL: false,
CALL: true,
SUPER_STATICCALL: false,
STATICCALL: false,
SUPER_DELEGATECALL: false,
DELEGATECALL: false,
DEPLOY: false,
SUPER_SETDATA: false,
SETDATA: false,
ENCRYPT: false,
DECRYPT: false,
SIGN: false,
EXECUTE_RELAY_CALL: false
}),
// '0x0000000000000000000000000000000000000000000000000000000000000110'

// Any ommited Permissions will default to false
ERC725.encodePermissions({
ADDCONTROLLER: true,
ADDEXTENSIONS: true,
}),
// '0x000000000000000000000000000000000000000000000000000000000000000a'
ERC725.encodePermissions({
EDITPERMISSIONS: true,
CHANGEEXTENSIONS: true,
CHANGEUNIVERSALRECEIVERDELEGATE: true,
SETDATA: true,
}),
// '0x0000000000000000000000000000000000000000000000000000000000040054'


// This method is also available on the instance:
myErc725.encodePermissions({
EDITPERMISSIONS: true,
SETDATA: true,
}),
```

---

## encodeValueType

```js
myErc725.encodeValueType(type, value);
```

```js
ERC725.encodeValueType(type, value);
```

#### Parameters

| Name | Type | Description |
| :------ | :--------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------- |
| `type` | string | The value type to encode the value (i.e. `uint256`, `bool`, `bytes4`, etc...). |
| `value` | string or <br/> string[&nbsp;] or <br/> number or <br/> number[&nbsp;] or <br/> boolean or <br/> boolean[] | The value that should be encoded as `type` |

#### Returns

| Name | Type | Description |
| :----------------- | :----- | :------------------------------------------------------- |
| `encodedValueType` | string | A hex string representing the `value` encoded as `type`. |

After the `value` is encoded, the hex string can be used to be stored inside the ERC725Y smart contract.

#### Examples

```javascript
myErc725.encodeValueType('uint256', 5);
// '0x0000000000000000000000000000000000000000000000000000000000000005'

myErc725.encodeValueType('bool', true);
// '0x01'

// the word `boolean` (Name of the Typescript type) is also available
myErc725.encodeValueType('boolean', true);
// '0x01'

// `bytesN` type will pad on the right if the value contains less than N bytes
myErc725.encodeValueType('bytes4', '0xcafe');
// '0xcafe0000'
myErc725.encodeValueType('bytes32', '0xcafe');
// '0xcafe000000000000000000000000000000000000000000000000000000000000'

// `bytesN` type will throw an error if the value contains more than N bytes
myERC725.encodeValueType('bytes4', '0xcafecafebeef');
// Error: Can't convert 0xcafecafebeef to bytes4. Too many bytes, expected at most 4 bytes, received 6.

// Can also be used to encode arrays as `CompactBytesArray`
myERC725.encodeValueType('uint256[CompactBytesArray]', [1, 2, 3]);
// '0x002000000000000000000000000000000000000000000000000000000000000000010020000000000000000000000000000000000000000000000000000000000000000200200000000000000000000000000000000000000000000000000000000000000003'

myERC725.encodeValueType('bytes[CompactBytesArray]', [
'0xaaaaaaaa',
'0xbbbbbbbbbbbbbbbbbb',
]);
// '0x0004aaaaaaaa0009bbbbbbbbbbbbbbbbbb'
```

This method is also available as a static method.

```javascript
ERC725.encodeValueType('string', 'Hello');
// '0x48656c6c6f'
```

---

## encodeKeyName
Expand Down Expand Up @@ -766,86 +999,6 @@ myErc725.decodeMappingKey(

---

## encodePermissions

```js
ERC725.encodePermissions(permissions);
```

Encodes permissions into a hexadecimal string as defined by the [LSP6 KeyManager Standard](https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager).

:::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

| Type | Description |
| :----- | :---------------------------------------------------------------------------------------- |
| string | The permissions encoded as a hexadecimal string defined by the [LSP6 KeyManager Standard] |

#### Example

```javascript title="Encoding permissions"
ERC725.encodePermissions({
CHANGEOWNER: false,
ADDCONTROLLER: false,
EDITPERMISSIONS: false,
ADDEXTENSIONS: false,
CHANGEEXTENSIONS: true,
ADDUNIVERSALRECEIVERDELEGATE: false,
CHANGEUNIVERSALRECEIVERDELEGATE: false,
REENTRANCY: false,
SUPER_TRANSFERVALUE: true,
TRANSFERVALUE: true,
SUPER_CALL: false,
CALL: true,
SUPER_STATICCALL: false,
STATICCALL: false,
SUPER_DELEGATECALL: false,
DELEGATECALL: false,
DEPLOY: false,
SUPER_SETDATA: false,
SETDATA: false,
ENCRYPT: false,
DECRYPT: false,
SIGN: false,
EXECUTE_RELAY_CALL: false
}),
// '0x0000000000000000000000000000000000000000000000000000000000000110'

// Any ommited Permissions will default to false
ERC725.encodePermissions({
ADDCONTROLLER: true,
ADDEXTENSIONS: true,
}),
// '0x000000000000000000000000000000000000000000000000000000000000000a'
ERC725.encodePermissions({
EDITPERMISSIONS: true,
CHANGEEXTENSIONS: true,
CHANGEUNIVERSALRECEIVERDELEGATE: true,
SETDATA: true,
}),
// '0x0000000000000000000000000000000000000000000000000000000000040054'


// This method is also available on the instance:
myErc725.encodePermissions({
EDITPERMISSIONS: true,
SETDATA: true,
}),
```

---

## fetchData

```js
Expand Down Expand Up @@ -1450,8 +1603,8 @@ Either a string of the hexadecimal `interfaceID` as defined by [ERC165](https://
| `LSP1UniversalReceiver` | [LSP-1: Universal Receiver](https://docs.lukso.tech/standards/generic-standards/lsp1-universal-receiver) |
| `LSP1UniversalReceiverDelegate` | [LSP-1: Universal Receiver Delegate](https://docs.lukso.tech/standards/universal-profile/lsp1-universal-receiver-delegate) |
| `LSP6KeyManager` | [LSP-6: Key Manager](https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager) |
| `LSP7DigitalAsset` | [LSP-7: Digital Asset](https://docs.lukso.tech/standards/tokens/LSP7-Digital-Asset) |
| `LSP8IdentifiableDigitalAsset` | [LSP-8: Identifiable Digital Asset](https://docs.lukso.tech/standards/tokens/LSP8-Identifiable-Digital-Asset) |
| `LSP7DigitalAsset` | [LSP-7: Digital Asset](https://docs.lukso.tech/standards/nft-2.0/LSP7-Digital-Asset) |
| `LSP8IdentifiableDigitalAsset` | [LSP-8: Identifiable Digital Asset](https://docs.lukso.tech/standards/nft-2.0/LSP8-Identifiable-Digital-Asset) |
| `LSP9Vault` | [LSP-9: Vault](https://docs.lukso.tech/standards/universal-profile/lsp9-vault) |

:::info
Expand Down
1 change: 0 additions & 1 deletion docs/tools/erc725js/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ If you install it on the backend side, you may need to also install [`isomorphic

```js
import { ERC725 } from '@erc725/erc725.js';
import Web3 from 'web3';

// Part of LSP3-UniversalProfile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-UniversalProfile.md
Expand Down
8 changes: 4 additions & 4 deletions docs/tools/lsp-factoryjs/deployment/digital-asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ The [LSP7] standard can be useful for NFT collections where you want all tokens

```javascript
await lspFactory.LSP7DigitalAsset.deploy({
isNFT: true,
controllerAddress: '0x56fE4E7dc2bc0b6397E4609B07b4293482E3F72B',
name: 'MYTOKEN',
symbol: 'DEMO',
isNFT: true,
controllerAddress: '0x56fE4E7dc2bc0b6397E4609B07b4293482E3F72B',
name: 'MYTOKEN'
symbol: 'DEMO',
});
```

Expand Down
Loading

0 comments on commit f0eacc1

Please sign in to comment.