Create a Marketplace

The backbone for a permissioned marketplace for you to mint tokens, create accounts, and to send to your users after purchase.

Overview

Understand that decentralisation is hard, many people don't have experience to use blockchain applications to use apps like Metamask and others. The role of this API and client is for you to build

Creating an account

Create and connect a hedera account to a user you have in your system, I would suggest either adding a new field on your users table or creating a new hedera_accounts table for a one-to-many relationship.

In this case I am using a simple approach that a user can only have one hedera account, thus three new fields have been added to a user migration.

  • encrypted_key

  • public_key

  • hedera_id

Imports

use Trustenterprises\LaravelHashgraph\LaravelHashgraph;
use Trustenterprises\LaravelHashgraph\Models\AccountCreateResponse;

Code

$account = LaravelHashgraph::createAccount(); // Returns AccountCreateResponse

// Get the Authorised user from a controller.
$user = \Auth::user();

// Update the fields of the user.
$user->encrypted_id = $account->getEncryptedKey();
$user->public_key = $account->getPublicKey();
$user->hedera_id = $account->getAccountId();

// Persist to storage.
$user->save();

Creating a token

Create a token that can be sent to a user's account after an event or a purchase.

Recommend that you create a new table to hold the details of a minted token. Use the returned tokenId at the primary key.

Imports

Code

Bequesting a token

Bequesting or sending a token to an account that has been generated, and linked to a user in your local database. This bypasses hedera's default association behaviour.

This is the magic element that provides a permissioned marketplace, the ability to send tokens of any asset to a user from any event.

Imports

Code

Last updated

Was this helpful?