Skip to content

Commit

Permalink
refactor: [DX-2625] update examples to use Unified SDK (#46)
Browse files Browse the repository at this point in the history
* update CODEOWNERS

* update user registration script

* add create project script

* update create collection script

* update add metadata schema script

* add minting script and minting utils

* refactor public method scripts

* remove unsed bulk minting script

* update utils

* update env examples

* remove admin scripts

* remove dockerfile

* remove unused docs

* update onboarding docs

* update public interfaces doc

* remove unused dependencies, update package.json scripts

* lock TS version to fix ESLint

* update create project instructions

* update metadata schema to match NFT minting tutorial

* update README

* update onboarding docs with clearer steps

* update lint workflow

* use node 18 in workflow

* remove yarn cache from workflow

* update ESLint

* lint fix
  • Loading branch information
CodeSchwert authored Apr 8, 2024
1 parent 8e8573f commit 3a6480f
Show file tree
Hide file tree
Showing 32 changed files with 14,658 additions and 9,341 deletions.
20 changes: 3 additions & 17 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@
#=============================================
ALCHEMY_API_KEY=
ETH_NETWORK=sepolia
# IMX API endpoint
PUBLIC_API_URL=https://api.sandbox.x.immutable.com/v1
# sandbox contracts in sepolia
STARK_CONTRACT_ADDRESS=0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98
REGISTRATION_ADDRESS=0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97
GAS_LIMIT=7000000
GAS_PRICE=40000000000

# Your environment's api key generated from https://hub.immutable.com/
API_KEY=
#=============================================
# Bulk Minting
#=============================================
PRIVATE_KEY1=
TOKEN_ID=
TOKEN_ADDRESS=
BULK_MINT_MAX=50

#=============================================
# Onboarding
#=============================================
# Your environment's api key generated from https://hub.immutable.com/
API_KEY=
OWNER_ACCOUNT_PRIVATE_KEY=
COLLECTION_CONTRACT_ADDRESS=
COLLECTION_PROJECT_ID=
COLLECTION_CONTRACT_ADDRESS=


#=============================================
Expand Down
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ module.exports = {
sourceType: 'module',
project: './tsconfig.eslint.json',
},
plugins: ['@typescript-eslint', 'simple-import-sort', 'fp-ts'],
plugins: ['@typescript-eslint', 'simple-import-sort', 'import'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:fp-ts/all',
'airbnb-typescript/base',
// @NOTE: Make sure this is always the last element in the array.
'plugin:prettier/recommended',
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @immutable/imx-developer-experience
* @immutable/sdk
34 changes: 6 additions & 28 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,19 @@ on:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-latest-4-cores
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check NPM Package Lock File Version
uses: mansona/npm-lockfile-version@v1

- name: Use Node.js 12.22.6
uses: actions/setup-node@v1
with:
node-version: 12.22.6

- name: Install npm 7.x
run: npm i -g npm@7
uses: actions/checkout@v3

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: node-modules
- name: Use Node.js
uses: actions/setup-node@v3
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
node-version: 18

- name: Install dependencies
run: npm ci
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div align="center">
<a href="https://www.immutable.com">
<img width="150" src="https://assets-global.website-files.com/5f7eec37ff782e797edabe11/5f8d36771ffcf8c91b03e7f4_dark.svg">
</a>
<br>
<br>
<p align="center">
<a href="https://docs.x.immutable.com/docs">
<img src="https://cdn.dribbble.com/users/1299339/screenshots/7133657/media/837237d447d36581ebd59ec36d30daea.gif" width="280"/>
</a>
</p>
</div>

---
Expand All @@ -14,16 +14,19 @@

This repository contains example scripts for interacting with Immutable X APIs.

## Guides

This repository is intended to be used alongside the Immutable X [NFT minting tutorial](https://docs.immutable.com/docs/x/zero-to-hero-nft-minting).

## Docs

* [Onboarding (Self Service)](docs/onboarding.md)
* [Administration](docs/administration.md)
* [Minting Assets](docs/minting-assets.md)
* [Public Interfaces](docs/public-interfaces.md)

## License

Immutable Examples repository is distributed under the terms of the [Apache License (Version 2.0)](LICENSE).

## Contributing

Please check [contributing guidelines](CONTRIBUTING.md) to learn how to help this project.
3 changes: 0 additions & 3 deletions docker-dev/Dockerfile

This file was deleted.

53 changes: 0 additions & 53 deletions docs/administration.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/minting-assets.md

This file was deleted.

91 changes: 72 additions & 19 deletions docs/onboarding.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Onboarding (Self-service)

## Pre-requisites

- Node.js v18 (LTS) or later.
- An Alchemy API key. You can create an account and get an API key following this [quickstart guide](https://docs.alchemy.com/docs/alchemy-quickstart-guide).
- A MetaMask wallet with some Sepolia testnet ETH. You can get testnet ETH from the [Etherem Sepolia faucet](https://www.alchemy.com/faucets/ethereum-sepolia).
- Alternatively, you can use the [Sepolia PoW faucet](https://sepolia-faucet.pk910.de/).
- You will need to export the private key of the wallet you want to use for onboarding.
- A collection contract deployed on Immutable X. You can deploy a collection contract following this [guide](https://github.com/immutable/contracts/blob/main/deploy/x/README.md)

### Immutable Developer Hub

Register with your email address at the [Immutable Developer Hub](https://hub.immutable.com) to get access to customized documentation in the hub as well as the ability to create Immutable X and Immutable zkEVM projects on Immutable.

You must first have a project in order to create collections that you can mint assets from on Immutable (L2).

For this onboarding guide, we will need to create an **Immutable X** project. Make sure you note down the Legacy ID of the project from the project overview page.

If you have already created an account, and have a Immutable X project, you can skip this step.

## Getting started

To begin, clone this repository:

```sh
Expand All @@ -14,30 +35,22 @@ Copy environment file
cp .env.example .env
```

Set the onboarding private key in `.env`. Your private key will be used to create a signed payload only and will not be sent to our backend services.

```sh
OWNER_ACCOUNT_PRIVATE_KEY=YOUR_PRIVATE_KEY
```

Set the `API_KEY` in the `.env` file. You can create and manage your API key in the [Immutable Hub](https://hub.immutable.com/). The Immutable Hub serves as a portal for creating, displaying, and refreshing API keys. Navigate to the "API Keys" menu item within your chosen project and environment to manage or create your API keys.
Set the environment variables in the `.env` file:

```sh
API_KEY=YOUR_SECRET_API_KEY
```
| Field Name | Description |
| ----------------------------- | ----------- |
| `ALCHEMY_API_KEY` | The Alchemy API key. |
| `API_KEY` | The API key generated from your environment's API Key page in the Immutable Hub. |
| `OWNER_ACCOUNT_PRIVATE_KEY` | Metamask private key. |
| `COLLECTION_PROJECT_ID` | The Legacy ID from your environment's overview page in the Immutable Hub. |
| `COLLECTION_CONTRACT_ADDRESS` | Deployed contract address. |

Install dependencies
Install project dependencies

```sh
npm install
```

## 0. Register with your email for the Immutable Developer Hub

Register with your email address at the [Immutable Developer Hub](https://hub.immutable.com) to get access to customized documentation in the hub as well as the ability to create projects on Immutable via the [Public API](https://docs.x.immutable.com/reference#/operations/createProject) or the CLI in this repo.

You must first have a project in order to create collections that you can mint assets from on Immutable (L2).

## 1. Register as a user with Immutable X

We provide an authentication service to protect your administrative level assets from being accessed or updated by someone else. This is done using a simliar technique as described [here](https://link.medium.com/CVTcj7YfQkb).
Expand All @@ -56,11 +69,15 @@ npm run onboarding:user-registration

Follow the guide at [here](https://docs.immutable.com/docs/x/launch-collection/register-project) to create a project in the [Immutable Hub](https://hub.immutable.com).

## 3. Add a collection
- Ensure you create a project for the **`Immutable X`** rollup.

## 3. Create a collection

A collection refers to a smart contract you have deployed. Minted assets belong to a collection. In order to mint assets on L2
you must first register your collection (smart contract) with Immutable X.

If you have not deployed a collection contract, you can follow the guide [here](https://github.com/immutable/contracts/blob/main/deploy/x/README.md) to deploy a Asset collection contract.

Add the collection contract address to the environment variable `COLLECTION_CONTRACT_ADDRESS`.

Set `COLLECTION_PROJECT_ID` to the legacy ID in your created environment's overview page from step 2.
Expand All @@ -81,9 +98,19 @@ npm run onboarding:create-collection

If you see a `replacement transaction underpriced` error message when trying to run `create-collection` please try again in 5 minutes.

There is a convenience script to get the info of the newly created collection:

```sh
npm run public:get-collection-info
```

The collection should also be visible in the [Immutable Hub](https://hub.immutable.com).

## 4. Add metadata schema to your collection

Update the values in file `4-add-metadata-schema.ts` with the values of the metadata you want to define.
Update the `4-add-metadata-schema.ts` file with the metadata schema values you want to define. The metadata schema is used to define the structure of the metadata that will be associated with the NFTs in your collection.

Descriptions of the metadata schema fields can be found [here](https://docs.immutable.com/docs/x/launch-collection/register-metadata-schema#metadata-schema).

Once updated, run the following script to create your collection:

Expand All @@ -92,3 +119,29 @@ _Requires environment variables `OWNER_ACCOUNT_PRIVATE_KEY` and `COLLECTION_CONT
```sh
npm run onboarding:add-metadata-schema
```

If you want to add additional metadata schemas, you can do so by adding more objects to the `metadata` array, and remove any existing metadata schemas from the `metadata` array, and then run the script again.

If you want to change the properties of an existing field, you can use the `updateMetadataSchemaByName` function instead. There is an example of this in the `4-add-metadata-schema.ts` file.

## 5. Mint NFTs

There is an minting example script, `5-mint-nfts.ts`, which is used to mint example NFTs to a wallet.

The default behaviour is to mint the NFTs to the wallet that owns the `OWNER_ACCOUNT_PRIVATE_KEY`. If you want to mint the NFTs to a different wallet, you can uncomment and update the `mintRecipient` value passed to the `mint` function in the script.

Also take a look at the example token objects in `tokens` array and update the blueprint values to your liking.

For a deeper explanation of the blueprint string, see the [Deep dive into metadata section] in the Immutable X documentation(https://docs.immutable.com/docs/x/deep-dive-metadata#providing-a-blueprint-string-when-token-is-minted-on-l2).

_Requires environment variables `OWNER_ACCOUNT_PRIVATE_KEY` and `COLLECTION_CONTRACT_ADDRESS` to be set._

```sh
npm run onboarding:mint
```

Once the NFTs have been minted, you can run the following script to get the info of the minted NFTs in the collection:

```sh
npm run public:get-assets-info
```
22 changes: 7 additions & 15 deletions docs/public-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@ These are the requests that can be made by anyone without authentication.

## Collections

## Get collection
Returns the collection information and associated metadata schema.

Returns the collection.
_Requires environment variables `COLLECTION_CONTRACT_ADDRESS` to be set._

```sh
npm run public:get-collection
npm run public:get-collection-info
```

### Get collections
## Assets

Update the query parameters in file `get-collections.ts`.
Returns a list of assets in a collection.

Once updated, run the following script to get collections:
_Requires environment variables `COLLECTION_CONTRACT_ADDRESS` to be set._

```sh
npm run public:get-collections
npm run public:get-assets-info
```

### Get collection metadata schema

Returns the collection's metadata schema.

```sh
npm run public:get-metadata-schema
```
Loading

0 comments on commit 3a6480f

Please sign in to comment.