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.
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:
pragma solidity = 0.5.0;contract AssetTokenized{uint public supply;uint public pricePerEth;mapping( address => uint ) public balance;constructor() public { supply = 1000; // There are a total of 1000 tokens for this asset pricePerEth = 100000000000000000; // One token costs 0.1 ether } function check() public view returns(uint) { return balance[msg.sender]; } function () external payable { balance[msg.sender] += msg.value/pricePerEth; // adds asset tokens to how much ether is sent by the investor supply -= msg.value/pricePerEth; //subtracts the remaining asset tokens from the total supply }}
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.