This tutorial describes how to create and transfer non-fungible assets on the Endless blockchain. The Endless no-code implementation for non-fungible digital assets can be found in the Move module.
Step 1: Pick an SDK
Install your preferred SDK from the below list:
TypeScript SDK
Step 2: Run the example
Clone the endless-ts-sdk repo and build it:
git clone https://github.com/endless-labs/endless-ts-sdk.git
cd endless-ts-sdk
pnpm install
pnpm build
Navigate to the Typescript ESM examples directory:
* Initializing the Endless client. * The creation of two accounts: Alice and Bob. * The funding and creation of Alice and Bob's accounts. * The creation of a collection and a token using Alice's account. * Alice sending a token to Bob.
The following output should appear after executing the simple_endless_token example, though some values will be different:
=== Addresses ===
Alice: 0x391f8b07439768674023fb87ae5740e90fb8508600486d8ee9cc411b4365fe89
Bob: 0xfbca055c91d12989dc6a2c1a5e41ae7ba69a35454b04c69f03094bbccd5210b4
=== Initial Coin Balances ===
Alice: 100000000
Bob: 100000000
=== Creating Collection and Token ===
Collection data: {
"address": "0x38f5310a8f6f3baef9a54daea8a356d807438d3cfe1880df563fb116731b671c",
"creator": "0x391f8b07439768674023fb87ae5740e90fb8508600486d8ee9cc411b4365fe89",
"name": "Alice's",
"description": "Alice's simple collection",
"uri": "https://endless.dev"
}
Token owner: Alice
Token data: {
"address": "0x57710a3887eaa7062f96967ebf966a83818017b8f3a8a613a09894d8465e7624",
"owner": "0x391f8b07439768674023fb87ae5740e90fb8508600486d8ee9cc411b4365fe89",
"collection": "0x38f5310a8f6f3baef9a54daea8a356d807438d3cfe1880df563fb116731b671c",
"description": "Alice's simple token",
"name": "Alice's first token",
"uri": "https://endless.dev/img/nyan.jpeg",
"index": "1"
}
=== Transferring the token to Bob ===
Token owner: Bob
=== Transferring the token back to Alice ===
Token owner: Alice
This example demonstrates:
* Initializing the REST and faucet clients. * The creation of two accounts: Alice and Bob. * The funding and creation of Alice and Bob's accounts. * The creation of a collection and a token using Alice's account. * Alice sending a token to Bob. * Bob sending the token back to Alice.
Step 4: The SDK in depth
Step 4.1: Initializing the clients
In the first step, the simple_digital_asset example initializes the Endless client:
const ENDLESS_NETWORK: Network =
NetworkToNetworkName[process.env.ENDLESS_NETWORK] || Network.DEVNET;
const config = new EndlessConfig({ network: ENDLESS_NETWORK });
const endless = new Endless(config);
By default, the Endless client points to Endless devnet services. However, it can be configured with the network input argument
In the first step, the example initializes both the API and faucet clients.
The API client interacts with the REST API.
The faucet client interacts with the devnet Faucet service for creating and funding accounts.
Using the API client we can create a TokenClient that we use for common token operations such as creating collections and tokens, transferring them, claiming them, and so on.
By default, the URLs for both the services point to Endless devnet services. However, they can be configured with the following environment variables:
ENDLESS_NODE_URL
ENDLESS_FAUCET_URL
Step 4.2: Creating local accounts
The next step is to create two accounts locally. Accounts consist of a public address and the public/private key pair used to authenticate ownership of the account. This step demonstrates how to generate an Account and store its key pair and address in a variable.
const alice = Account.generate();
const bob = Account.generate();
Note that this only generates the local keypair. After generating the keypair and public address, the account still does not exist on-chain.
Step 4.3: Creating blockchain accounts
In order to actually instantiate the Account on-chain, it must be explicitly created somehow. On the devnet network, you can request free coins with the Faucet API to use for testing purposes. This example leverages the faucet to fund and inadvertently create Alice and Bob's accounts:
Now begins the process of creating the digital, non-fungible assets. First, as the creator, you must create a collection that groups the assets. A collection can contain zero, one, or many distinct fungible or non-fungible assets within it. The collection is simply a container, intended only to group assets for a creator.
Your application will call createCollectionTransaction and then signAndSubmitTransaction to chain:
To create a token, the creator must specify an associated collection. A token must be associated with a collection, and that collection must have remaining tokens that can be minted. There are many attributes associated with a token, but the helper API exposes only the minimal amount required to create static content.
Both the collection and token assets are Objects on-chain with unique addresses. Their metadata is stored at the object address. The SDKs provide convenience wrappers around querying this data:
Each object created from the endless_token.move contract is a distinct asset. The assets owned by a user are stored separately from the user's account. To check if a user owns an object, check the object's owner:
Each object created from the endless_token.move contract is a distinct asset. The assets owned by a user are stored separately from the user's account. To check if a user owns an object, check the object's owner: