Ethereum: Asset Tokenization with Embark
- You’ll build a simple contract in Embark that tokenizes assets with a fixed supply of 1,000 tokens.
- You’ll set a price of 0.1 ether per token and let anyone exchange ether for asset tokens on Sepolia.
- You’ll use Chainstack to deploy and run your own Sepolia node, and Geth to manage your accounts.
- You’ll confirm everything works by testing the contract with Embark’s Cockpit and by sending ether from MetaMask.
Main article
This tutorial will guide you through creating a tokenized asset contract and deploying it on Sepolia testnet.
For illustration purposes, this contract does the following:
- Creates a total supply of 1,000 tokens specific to the asset.
- Sets the token price to 0.1 ether.
- Let anyone exchange ether for asset tokens. This tutorial uses Embark to test and deploy the contract.
Prerequisites
- Chainstack account to deploy a Sepolia testnet node.
- Embark to test and deploy the contract.
- Geth to create an Ethereum account that will deploy the contract.
- MetaMask to interact with the contract.
Overview
To get from zero to an asset tokenization contract running on Sepolia, do the following:
With Chainstack, create a .
With Chainstack, deploy a Sepolia testnet node.
With Embark, create a project and the contract.
With Geth, create a new account.
Import the account in MetaMask and fund the account with Sepolia ether.
With Embark, deploy the contract through the Sepolia node.
With Embark, check the contract with Cockpit.
Interact with the contract through MetaMask.
Step-by-step
Create a public chain project
See Create a project.
Deploy a Sepolia node
Get Sepolia testnet ether from a faucet
In your MetaMask, fund each account with Sepolia ether Chainstack’s Sepolia faucet.
Create an Embark project and the contract
Create a new Embark project:
This will create an Embark directory called asset
.
Change to the contracts
directory of the Embark project.
Create an AssetTokenized.sol
file in the contracts
directory:
Create an Ethereum account
You will use this account to deploy the contract.
Create the account:
Check the path to the keystore file created for the new account:
Import the account in MetaMask and fund the account
In MetaMask, click Import Account > JSON File.
Select the keystore file that you created earlier.
Fund the account with Sepolia ether.
Deploy the contract
In your Embark project directory, change to config
.
Append contracts.js
with the following configuration:
where
//root/.ethereum/keystore/...
— the location of the keystore file- PASSWORD — the password you provided when creating the Ethereum account with Geth
- YOUR_CHAINSTACK_ENDPOINT — your Chainstack node endpoint. See also View node access and credentials.
Deploy the contract with Embark:
where chainstack
— the argument from the configuration file contracts.js
This will deploy the contract on Sepolia.
Check the contract with Cockpit
On contract deployment, Embark runs Cockpit which is a front-end application to test the contract.
In your browser, open:
<http://localhost:55555/explorer/contracts/CONTRACT_NAME>
where CONTRACT_NAME — the name of your contract. In this tutorial, the path is <http://localhost:55555/explorer/contracts/AssetTokenized>
.
This will also display the contract address in the Deployed at
line.
Test the contract by calling:
supply()
— to check the remaining supply of tokens on the contract.check()
— to check the amount of tokens owned by the Ethereum address you are using to call the contract.pricePerEth()
— to check the token price in wei.
Interact with the contract
- In MetaMask, send an amount of Sepolia ether to the contract address.
- In Cockpit, call the contract functions
supply()
andcheck()
after a few seconds to see a change in values returned.