This is a simple, one-page app that integrates with Mysten Lab's Enoki. The live testnet demo can be foud here.
Follow the steps below to run your own instance of the app locally.
- Clone/fork the repository and navigate to the root directory.
- Set up your Enoki API keys
- Set up your google client id and Enoki Auth Provider.
- Deploy and connect your smart contract.
- Set up your Enoki Sponsored Transactions.
- Install the dependencies by running
yarn install
. - Start the app by running
yarn dev
. - Try out your app by logging in with Google and creating a counter!
In order to use Enoki, you need to sign into the Enoki Dev Portal and set up your new project. Below are the steps required for this.
-
Navigate to the Enoki Dev Portal and sign in with the email you want to manage your project with.
Note, that during your first time signing in, you'll be asked to provide some info to help Mysten Labs keep informed about who is using Enoki. You will also be prompted to select your payment plan. Go ahead and skip this for now.
The portal should look something like this when you successfully log on:
-
Click
+ Create your first App
and enter the name of your app. -
Click
+ Create new
underNew API Key
.You will be given a prompt that looks like this:
You'll need to create two keys: one for the zkLogin feature used in the client and one for the sponsored transactions feature used in the backend.
-
zkLogin key:
- API key type:
Public
- Enabled networks:
Testnet
- Enabled features:
zkLogin
- API key type:
-
Sponsored transactions key:
- API key type:
Private
- Enabled networks:
Testnet
- Enabled features:
Sponsored transactions
- API key type:
-
-
Now you have your Enoki API keys!
To use the key in this demo, make a copy of .env.template named
.env
, and .env.local.template named.env.local
and paste the public and private key intoNEXT_PUBLIC_ENOKI_API_KEY
andENOKI_SECRET_KEY
respectively. It should look something like this:NEXT_PUBLIC_ENOKI_API_KEY=enoki_public_aa763a9d36bb6aa1e41062dd67df2518
ENOKI_SECRET_KEY=enoki_private_905204de81012fd7422a9902907f112c
You have successfully set up your Enoki API keys! Continue to the next steps in setting up your app
To use the zkLogin feature, you will need to connect your auth provider to the Enoki Dev Portal.
-
Navigate to the
Auth Providers
section of your Enoki project.The Auth Providers section is where you can add and manage your app's auth providers.
-
Click
+ New Auth Provider
You will be given a prompt that looks like this:
When creating a key for this demo app, select
Google
and paste your google client id. Follow the instructions to get your client id from Google. -
Now you have your Enoki Auth Provider!
Paste the client id into the
.env
file. It should look something like this:NEXT_PUBLIC_GOOGLE_CLIENT_ID=277348171272-epn1s82k6bmumooapalnsdq0lu19d27t.apps.googleusercontent.com
Note that you can add more auth providers by repeating the steps above.
-
You have successfully connected your auth provider to Enoki! Continue to the next steps in setting up your app
In the Enoki Dev Portal, you can set up Sponsored Transactions by adding addresses and move targets that are supported.
-
Navigate to the
Sponsored Transactions
section of your Enoki project.The Sponsored Transactions section is where you can add and manage the addresses and move targets that you want to be supported in sponsored transactions.
-
Add the addresses and move call targets you want to be supported.
Any allowed addresses are senders that can use sponsored transactions. Any allowed move call targets are functions operations that any of your users can use sponsored transactions for.
This app supports the following move call targets:
{PACKAGE_ID}::counter::create
{PACKAGE_ID}::counter::increment
{PACKAGE_ID}::counter::set_value
NOTE: Use the package ID you got from deploying your smart contract to get the move call targets. Replace
{PACKAGE_ID}
with the package ID you got from deploying your smart contract. -
You have successfully set up your Enoki Sponsored Transaction allow list! Continue to the next steps in setting up your app
You will need to set up a Google Auth API key to use the Google Sign-In feature in this demo app.
-
Navigate to the Google Developers Console.
-
Click
+ Create Credentials
and selectOAuth client ID
. -
Select
Web application
as the application type. -
Add
http://localhost:3000/auth
to theAuthorized redirect URIs
. -
Click
Create
and copy the client id. -
You can now paste this client id into the
.env
file as described in the Setting up your Enoki Auth Provider section.
This demo app uses a simple Sui smart contract that allows anyone to create global counters that anyone can increment but only the creator can reset. To deploy this contract, follow the steps below:
-
Navigate to Move Studio IDE.
-
Click
New Project
and selectUpload
. -
Select
Choose File
and choose the Counter Sui module directory. -
Click
Deploy
under theTools
section in the left sidebar and approve the transaction in your wallet. -
After the package window appears, copy the package ID and paste it into the
.env.local
file as thePACKAGE_ID
variable. It should look something like this:PACKAGE_ID=0x7b6a8f5782e57cd948dc75ee098b73046a79282183d51eefb83d31ec95c312aa