- Minting: Minting of tokens to your wallet from the Sequence Builder
- Wallet Authentication: Use of Web SDK to authenticate a user
- Blockchain Queries: Querying of token balances using the Indexer
- Multi-wallet Types: Allow users to either use a Sequence Wallet or an EOA
- Request Creation: Creation of sell listing requests on the Sequence Market Protocol
- Order Accepting: Accepting of top orders from the Marketplace
- (Optional) Enable Embedded Wallet: Add a more seamless UX experience with no-confirmation transactions
See an example simplified marketplace dapp that enables users to mint collectibles, sell the collectibles with the Sequence Marketplace Protocol, and make purchases with USDC on
base-sepolia by getting a top order from the Marketplace.The code can be found here1. Minting
The first step is to create a collectible from the Sequence Builder and mint a few tokens, which can be accomplished with this guide and to use thetokenId you minted in the following steps to query and fulfill orders.
2. Wallet Authentication
For your project, you’ll need a way to authenticate your user with a wallet. Your choice from the Sequence stack is to use either an Embedded Wallet for headless and web2-like UX, or a Ecosystem Wallet with Web SDK to reach more types of wallets. For this guide we’ll use anUniversal Sequence Wallet with Web SDK connector (with an option for an Embedded Wallet) which can authenticate users using Google or Apple auth, in addition to user brought wallets like Coinbase or Metamask.
Install Packages
Either you can create a vanilla js/html/css project from a template like this for a templated setup, or we will walk you through how to use react from scratch here. Start by creating a project in a folder of your name choosing:<project_name> folder
src next to index.tsx in the folder, create a config.ts file with the following contents:
config to be consumed by the WagmiProvider in the index.tsx
App.tsx to make the Web SDK modal appear
3. Blockchain Queries
Once you have one or a few collectibles minted, you can query the data from the contract address from your deployment, which can be found here:
tokenID to create a request on the marketplace, for this demo we’ll assume you’re dealing with a single tokenID
Example Response
Example Response
-
contractType(string) - the type of contract type (i.e. ERC20, ERC721, or ERC1155) -
contractAddress(string) - the contract address of the token -
accountAddress(string) - the deploying account address -
tokenID(string) - the tokenID of the token (always 0 if ERC20) -
balance(string) - the balance of the token -
blockHash(string) - the transaction merkle hash of the block when the token was deployed -
blockNumber(number) - the blocknumber the token was deployed -
chainId(number) - the chain id of the token -
contractTypechainId(number) - the chain id of the tokenaddress(string) - the address of the tokenname(string) - contract level name of the tokentype(string) - the type of contract type (i.e. ERC20, ERC721, or ERC1155)symbol(string) - the symbol of the tokendecimals(number) - the number of decimals the token haslogoURI(string) - the logo of the token displayed in sequence.appdeployed(boolean) - whether the token is deployedbytecodeHash(string) - hash of the bytecode of a smart contract deployed on the blockchainextensionslink(string) - the adjoining website to link to the projectdescription(string) - the metadata description of the tokenogImage(string) - the banner image for the token, rendered in sequence.apporiginChainId(number) - the originating chain id the token representsoriginAddress(string) - the originating contract address the token representsverified(boolean) - whether the token is verified and trustedverifiedBy(string) - the verifing source as to why this is not spam
-
updatedAt(date) - the last time the indexer was updated -
tokenMetadatatokenId(string) - the tokenID of the token (always 0 if ERC20)contractAddress(string) - the contract address of the tokenname(string) - token level namedescription(string) - the description of the tokenimage(string) - the image as a url of the tokendecimals(string) - the number of decimals for the tokenproperties(object) - an object containing the properties of the token metadataexternal_url(string) - an external url for where to find the token or more detailsupdatedAt(date) - the last time the token metadata was updated
4. Multi-wallet Types
Due to the fact that we’re usingWeb SDK for this example that allows you to use a Sequence wallet, in addition to your own brought EOA wallet, sending transactions to the blockchain will differ due to the fact that with a Sequence wallet, you can send batch transactions to optimize gas costs, whereas with wagmi using an EOA you can only send 1 transaction at a time.
To accomplish this, we take a few steps to create a local state variable that checks for the authorized wallet
In the Sequence Market protocol, when you create a listing, it’s referred to
as a
request, and when you accept a request it’s called an order.5. Request Creation
For this example, we’ll be usingArbitrum Sepolia USDC from the community faucet
Head over there to first get some tokens, so that you can make listing with your request
Then, in order to create a request for the orderbook, we’ll need to first make sure we enable the marketplace orderbook contract with approval to transfer your tokens First, we check that the marketplace is approved for the contract, with some logic
useSendTransaction hook using a mutex to confirm which transaction the hash came from. This is done in a react useEffect function.
In computer programming, a mutual exclusion (mutex) is a program object that
prevents multiple threads from accessing the same shared resource
simultaneously.
6. Order Accepting
Now that we have an order on the marketplace, we need to do a few things:Query the Marketplace: query the marketplace for anorderIdthat you want to accept an order forCurrency Balance: check for currency balance using the indexerToken Approval: check for currency approval for the marketplace to transfer tokens
Query the Marketplace
Lets query the marketplace orderbook to get thepricePerToken and orderId the order is for
Currency Balance
We’ll use the indexer to query the balance and see if the user has enough token to pay for the order. This can be accomplished with the following code:Token Approval
Next, we’ll check for token approval for the Marketplace to be able to transfer the currency tokenuseEffect with the mutex check implemented like before
7. (Optional) Integrate Embedded Wallet into Web SDK
In order to make your Web SDK connector as Embedded Wallet enabled, we’ll need to install a few package version and update ourconfig.ts we used at the beginning of the guide
The Embedded Wallet feature allows no-confirmation transactions, which can create a smoother UX