Your First Transaction
Last updated
Last updated
This tutorial describes how to generate and submit transactions to the Endless blockchain, and verify these submitted transactions. The transfer-coin
example used in this tutorial is built with the Endless SDKs.
Install your preferred SDK from the below list:
TypeScript SDK
Rust SDK
Clone the endless-ts-sdk repo and build it:
Navigate to the Typescript examples directory:
Install the necessary dependencies:
Run the example:
Clone the endless-core repo:
Rust
Clone the endless-core repo:
Navigate to the Rust SDK directory:
An output very similar to the following will appear after executing the above command:
The above output demonstrates that the transfer-coin
example executes the following steps:
Initializing the Endless client.
The creation of two accounts: Alice and Bob.
The funding and creation of Alice's account from a faucet.
The transferring of 1000000 coins from Alice to Bob.
The 100500 coins of gas paid for by Alice to make that transfer.
Now see the below walkthrough of the SDK functions used to accomplish the above steps.
In the first step, the transfer_coin
example initializes the Endless client:
In the first step, the `transfer_coin` example initializes the REST and indexer clients:
The REST client interacts with the REST API.
The indexer client interacts with the tesnet indexer service for complex searching.
The next step is to create two accounts locally. Accounts represent both on and off-chain state. Off-chain state consists of an address and the public/private key pair used to authenticate ownership. This step demonstrates how to generate that off-chain state.
In Endless, each account must have an on-chain representation in order to receive tokens and coins and interact with other dapps. An account represents a medium for storing assets; hence, it must be explicitly created. This example leverages the Faucet to create and fund Alice's account and to create but not fund Bob's account:
In this step, the SDK translates a single call into the process of querying a resource and reading a field from that resource.
Behind the scenes, the balance
function uses the SDK viewCoinBalance
function that reads the FungibleStore stored value:
Like the previous step, this is another helper step that constructs a transaction transferring the coins from Alice to Bob. The SDK provides a helper function to generate a transferEDS
transaction that can be simulated or submitted to chain. Once a transaction has been submitted to chain, the API will return a transaction hash that can be used in the subsequent step to check on the transaction status. The Endless blockchain does perform a handful of validation checks on submission; and if any of those fail, the user will instead be given an error. These validations use the transaction signature and unused sequence number, and submitting the transaction to the appropriate chain.
Behind the scenes, the transferEDS
function generates a transaction payload that can be simulated or submitted to chain:
Breaking the above down into pieces:
The Move function is stored on the endless_account module: 0x1::endless_account
.
Like the previous step, this is another helper step that constructs a transaction transferring the coins from Alice to Bob. For correctly generated transactions, the API will return a transaction hash that can be used in the subsequent step to check on the transaction status. The Endless blockchain does perform a handful of validation checks on submission; and if any of those fail, the user will instead be given an error. These validations use the transaction signature and unused sequence number, and submitting the transaction to the appropriate chain.
In the TypeScript SDK, just calling waitForTransaction
is sufficient to wait for the transaction to complete. The function will return the Transaction
returned by the API once it is processed (either successfully or unsuccessfully) or throw an error if processing time exceeds the timeout.
The transaction hash can be used to query the status of a transaction:
Run the example:
The transfer-coin
example code uses helper functions to interact with the . This section reviews each of the calls and gives insights into functionality.
See the full code See the TypeScript for the complete code as you follow the below steps.
transfer_coins
internally is a EntryFunction
in the , i.e. an entry function in Move that is directly callable.