-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SmartTokenLabs/refactor/implement-erc5169
refactor: 💡 update ERC5169 doc
- Loading branch information
Showing
2 changed files
with
39 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
# How to implement ERC5169 | ||
# How to implement ERC-5169 | ||
|
||
1. Install [stl-contracts](https://www.npmjs.com/package/stl-contracts) NPM module with command ```npm i stl-contracts``` | ||
Implementing ERC-5169 can be conveniently achieved by inserting several lines of code. | ||
|
||
2. Add next code to your contract | ||
1. Install [stl-contracts](https://www.npmjs.com/package/stl-contracts) package: | ||
|
||
```sh npm2yarn copy | ||
npm i stl-contracts | ||
``` | ||
|
||
2. Add following code to your contract | ||
|
||
```solidity copy | ||
import "stl-contracts/ERC/ERC5169.sol"; | ||
contract ERC721Mint is Ownable, ERC5169, AccessControl, ERC721Enumerable { | ||
function supportsInterface(bytes4 interfaceId) | ||
public view override(ERC5169, ERC721Enumerable) | ||
returns (bool) | ||
{ | ||
return | ||
ERC721Enumerable.supportsInterface(interfaceId) || | ||
ERC5169.supportsInterface(interfaceId); | ||
function supportsInterface(bytes4 interfaceId) public view override(ERC5169, ERC721Enumerable) returns (bool) { | ||
return ERC721Enumerable.supportsInterface(interfaceId) || ERC5169.supportsInterface(interfaceId); | ||
} | ||
// limit set contracts to admin only | ||
function _authorizeSetScripts(string[] memory) internal view override(ERC5169) onlyOwner {} | ||
} | ||
``` | ||
|
||
3. In case if you don't implement **Ownable** interface then replace **onlyOwner** with your modifier to limit use of **_authorizeSetScripts** to admin or other user/group | ||
3. In case if you don't implement **`Ownable`** interface then replace **`onlyOwner`** with your modifier to limit use of **`_authorizeSetScripts`** to admin or other user/group | ||
|
||
4. When contract deployed run command to add script to your contract | ||
4. When contract deployed run the following script to set the `scriptURI` | ||
|
||
``` | ||
let scripts = ["https://your.hosting.com/messaging_mumbai.tsml"] | ||
```js {8} copy | ||
const [owner] = await ethers.getSigners(); | ||
const ERC721Mint = await ethers.getContractFactory("ERC721Mint"); | ||
|
||
const ERC721Mint = await ethers.getContractFactory('ERC721Mint'); | ||
const nft = await ERC721Mint.attach(contractAddress); | ||
let tx = await nft.connect(owner).setScriptURI(scripts) | ||
|
||
let tx = await nft | ||
.connect(owner) | ||
.setScriptURI(['https://your.hosting.com/messaging_mumbai.tsml']); | ||
await tx.wait(); | ||
``` | ||
|
||
When script added then NFTs (which user own) for this contract will appear under [Smart Token Store](https://smart-token-store.vercel.app/) | ||
When script added then NFTs (which user own) for this contract will appear under [Smart Token Store](https://store.smartlayer.network/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
# How to build Secure Messaging between ERC721 NFT owners | ||
|
||
1. Install tokenscript CLI by running command ```npm i -g @tokenscript/cli``` | ||
1. Clone Token Messaging template from the [Template Center](https://github.com/SmartTokenLabs/TokenScript-Templates) | ||
|
||
2. Clone Git repo https://github.com/SmartTokenLabs/TokenScript-Templates - its list of TokenScript Templates | ||
```sh copy | ||
npx degit SmartTokenLabs/TokenScript-Templates/erc-721-messaging erc-721-messaging | ||
``` | ||
|
||
3. Open folder ```/erc-721-messaging``` | ||
2. Open folder `/erc-721-messaging` | ||
|
||
4. Replace Contract Address and chain ID in /tokenscript.xml, example: | ||
3. Replace Contract Address and chain ID in /tokenscript.xml, example: | ||
|
||
``` | ||
```xml | ||
<ts:contract interface="erc721" name="Token"> | ||
<ts:address network="80001">0xe84Be2e18304AcF07ba2f11e37EABC321f4DC6Df</ts:address> | ||
</ts:contract> | ||
``` | ||
|
||
5. Run command ```npm i``` to install all dependencies | ||
4. Install TokenScript CLI: | ||
|
||
```sh npm2yarn copy | ||
npm i -g @tokenscript/cli | ||
``` | ||
|
||
5. Run command `npm i` to install all dependencies | ||
|
||
6. Run command ```npm run build``` to build TSML file **out/tokenscript.tsml** | ||
6. Run command `npm run build` to build TSML file **out/tokenscript.tsml** | ||
|
||
7. Run ```tokenscript emulate``` to preview your tokenscript in action | ||
7. Run `tokenscript emulate` to preview your tokenscript in action | ||
|
||
8. If TokenScript works as expected then copy file **out/tokenscript.tsml** to some HTTPS hosting and save file URL | ||
|
||
Now you can use this URL in tokenscript viewer. Don't forget to replace variables with values **chainId** , **contractAddress** and replace **tokenScriptFileURL** with its value, its URL, where TSML file located. | ||
|
||
This is template of TokenScript viewer for your TokenScript file: | ||
|
||
``` | ||
```sh | ||
https://viewer-staging.tokenscript.org/?chain=${chainId}&contract=${contractAddress}&tokenscriptUrl=${encodeURIComponent(tokenScriptFileURL)} | ||
``` | ||
|
||
|
||
|
||
Thats it, ready for messaging. | ||
|