Token¶
Welcome to our guide on launching a token collection using the Koinos Contract Standard (KCS-1) for tokens and the AssemblyScript SDK for Koinos. In this tutorial, we'll walk you through the process of creating and deploying your own token on the Koinos blockchain. Whether you're a seasoned developer or new to blockchain development, this step-by-step guide will provide you with the knowledge and tools necessary to bring your token project to life. Let's dive in and explore the exciting world of token creation on Koinos!
Before starting, ensure that you have already set up your Koinos AssemblyScript SDK environment by following this guide.
Setting up the project¶
Let's begin by creating a boilerplate smart contract project using the Koinos AssemblyScript SDK.
koinos-sdk-as-cli create token
Generating contract at "/home/$USER/Workspace/token" ...
Contract successfully generated!
You're all set! Run the following set of commands to verify that the generated contract is correctly setup:
cd /home/$USER/Workspace/token && yarn install && yarn build:debug && yarn test
Change your directory to the project directory and install dependencies.
cd token
yarn install
yarn install v1.22.19
warning ../../../../../package.json: No license field
info No lockfile found.
[1/4] 🔍 Resolving packages...
warning @koinos/sdk-as > @koinos/mock-vm > multibase@4.0.6: This module has been superseded by the multiformats module
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > @npmcli/ci-detect@2.0.0: this package has been deprecated, use `ci-info` instead
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > libnpmexec > @npmcli/ci-detect@2.0.0: this package has been deprecated, use `ci-info` instead
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > @npmcli/arborist > readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > @npmcli/arborist > @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > cacache > @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
warning @koinos/sdk-as > @koinos/mock-vm > somap > npm > readdir-scoped-modules > debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning local-koinos > koilib > multibase@4.0.6: This module has been superseded by the multiformats module
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning "@koinos/sdk-as > @as-covers/core > @as-covers/transform > visitor-as@0.6.0" has incorrect peer dependency "assemblyscript@^0.18.31".
warning " > ts-node@10.9.2" has unmet peer dependency "@types/node@*".
warning Workspaces can only be enabled in private projects.
[4/4] 🔨 Building fresh packages...
success Saved lockfile.
✨ Done in 12.96s.
Defining methods and data¶
Building a contract will usually consist of behaviors and data. The behavior is defined by the smart contract. But the data is defined by Protobuf. We generate data structures with Protobuf so that the smart contract can easily integrate with other Koinos tools. We have defined the arguments and results we will use in our calculator. We use the *_arguments
convention for contract function arguments and *_result
for contract function results.
Let's begin by defining our entry point arguments and results.
vi assembly/proto/token.proto
Currently, the token.proto
file contains the following boilerplate code:
assembly/proto/token.proto | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
We can remove the boilerplate code and replace it with our token arguments and results.
assembly/proto/token.proto | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
koinos-sdk-as-cli generate-contract-proto
Generating Contract AS proto files...
yarn protoc --plugin=protoc-gen-as=./node_modules/.bin/as-proto-gen --as_out=. assembly/proto/*.proto
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ ../token-tutorial/token/node_modules/.bin/protoc --plugin=protoc-gen-as=./node_modules/.bin/as-proto-gen --as_out=. assembly/proto/token.proto
Done in 0.78s.
assembly/proto/token.ts
was automatically generated and contains code that will assist us in serializing and deserializing data in and out of the KVM.
The implementation¶
Now, we have defined the data in which arguments come into our contract and also the data which is returned by our contract. All we need now is our implementation.
Let's use the tools to automatically generate the boilerplate implementation.
koinos-sdk-as-cli generate-contract-as token.proto
Generating boilerplate.ts and index.ts files...
yarn protoc --plugin=protoc-gen-as=./node_modules/.bin/koinos-as-gen --as_out=assembly/ assembly/proto/token.proto
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ /Users/$USER/Workspace/token/token/node_modules/.bin/protoc --plugin=protoc-gen-as=./node_modules/.bin/koinos-as-gen --as_out=assembly/ assembly/proto/token.proto
Done in 1.31s.
After invoking this command, we have two newly generated files. The first is assembly/index.ts
which is the first location our smart contract codes begin executing. This file acts as a router to call the appropriate method on our class because of how the smart contract was invoked.
The second file that was generated is assembly/Token.boilerplate.ts
. This is where our implementation lives. We should rename this file to Token.ts
and begin our implementation.
rm assembly/Token.ts
mv assembly/Token.boilerplate.ts assembly/Token.ts
vi assembly/Token.ts
Let's open our implementation file and write logic to add our token's functionality.
assembly/Token.ts | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
We have to add assembly/state
directory where we define our storage.
mkdir assembly/state && touch assembly/state/BalancesStorage.ts assembly/state/SpaceIds.ts assembly/state/SupplyStorage.ts
Create the above files and add this code to each:
assembly/state/BalancesStorage.ts | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
assembly/state/SpaceIds.ts | |
---|---|
1 2 |
|
assembly/state/SupplyStorage.ts | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Time for tests¶
Let's open up assembly/__tests__/Calculator.spec.ts
and write some tests.
assembly/__tests__/Token.spec.ts | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
|
Run the build debug command
koinos-sdk-as-cli build debug 0
Compiling index.ts...
node ./node_modules/assemblyscript/bin/asc assembly/index.ts --target debug --use abort= --use BUILD_FOR_TESTING=0 --disable sign-extension --config asconfig.json
And now let's run the tests
koinos-sdk-as-cli run-tests
Running tests...
yarn asp --verbose --config as-pect.config.js
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ /path/to/token/node_modules/.bin/asp --verbose --config as-pect.config.js
___ _____ __
/ | / ___/ ____ ___ _____/ /_
/ /| | \__ \______/ __ \/ _ \/ ___/ __/
/ ___ |___/ /_____/ /_/ / __/ /__/ /_
/_/ |_/____/ / .___/\___/\___/\__/
/_/
⚡AS-pect⚡ Test suite runner [6.2.4]
[Log] Loading asc compiler
Assemblyscript Folder:assemblyscript
[Log] Compiler loaded in 165.113ms.
[Log] Using configuration /path/to/token/as-pect.config.js
[Log] Using VerboseReporter
[Log] Including files: assembly/__tests__/**/*.spec.ts
[Log] Running tests that match: (:?)
[Log] Running groups that match: (:?)
[Log] Effective command line args:
[TestFile.ts] node_modules/@as-pect/assembly/assembly/index.ts --runtime incremental --debug --binaryFile output.wasm --explicitStart --use ASC_RTRACE=1 --exportTable --importMemory --transform /path/to/token/node_modules/@as-covers/transform/lib/index.js,/path/to/token/node_modules/@as-pect/core/lib/transform/index.js --lib node_modules/@as-covers/assembly/index.ts
[Describe]: token
[Success]: ✔ should get the name RTrace: +26
[Success]: ✔ should get the symbol RTrace: +26
[Success]: ✔ should get the decimals RTrace: +22
[Success]: ✔ should get the max supply RTrace: +22
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Event] koinos.contracts.token.burn_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EAo=
[Contract Exit] 'from' has insufficient balance
[Contract Exit] 'from' has not authorized transfer
[Success]: ✔ should/not burn tokens RTrace: +656
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Success]: ✔ should mint tokens RTrace: +281
[Contract Exit] account '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe' authorization failed
[Success]: ✔ should not mint tokens if not contract account RTrace: +207
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqK' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc6EHs=
[Contract Exit] Mint would overflow supply
[Success]: ✔ should not mint tokens if new total supply overflows RTrace: +338
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqK' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc6EHs=
[Contract Exit] Mint would overflow max supply
[Success]: ✔ should not mint tokens if new total supply overflows max supply RTrace: +338
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Event] koinos.contracts.token.transfer_event / [
'1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqK',
'1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG'
] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EhkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc6GAo=
[Success]: ✔ should transfer tokens RTrace: +391
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Contract Exit] 'from' has not authorized transfer
[Success]: ✔ should not transfer tokens without the proper authorizations RTrace: +295
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Contract Exit] Cannot transfer to self
[Success]: ✔ should not transfer tokens to self RTrace: +234
[Event] koinos.contracts.token.mint_event / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqG' ] / ChkAiCtotTmdMTyQZ/OEFgfmKMEtVCA8jEc3EHs=
[Contract Exit] 'from' has insufficient balance
[Success]: ✔ should not transfer if insufficient balance RTrace: +307
[File]: assembly/__tests__/Token.spec.ts
[Groups]: 2 pass, 2 total
[Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
[Summary]: 13 pass, 0 fail, 13 total
[Time]: 131.568ms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Result]: ✔ PASS
[Files]: 1 total
[Groups]: 2 count, 2 pass
[Tests]: 13 pass, 0 fail, 13 total
[Time]: 4894.475ms
┌───────────────────┬───────┬───────┬──────┬──────┬───────────┐
│ File │ Total │ Block │ Func │ Expr │ Uncovered │
├───────────────────┼───────┼───────┼──────┼──────┼───────────┤
│ assembly/Token.ts │ 100% │ 100% │ 100% │ 100% │ │
├───────────────────┼───────┼───────┼──────┼──────┼───────────┤
│ total │ 100% │ 100% │ 100% │ 100% │ │
└───────────────────┴───────┴───────┴──────┴──────┴───────────┘
Done in 5.19s.
Customizing the token¶
Let's customize the specifics of our token project by modifying ./assembly/Token.ts
. Define the following:
-
_name
: The name of your token -
_symbol
: The symbol for your token -
_decimals
: The decimal places for your token
Let's change the default values to the name and symbol of our token.
assembly/Token.ts | |
---|---|
9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
In the highlighted lines we changed the [token name]
variable to My Token Name
and the symbol
variable to MTN
.
Keep in mind that since this token name and symbol have already been minted to the testnet you should replace your own name and symbol with the ones used in this guide.
Let's run the tests again and see what happens.
koinos-sdk-as-cli run-tests
[Describe]: token
[Fail]: ✖ should get the name
[Actual]: "My Token Name"
[Expected]: "[token name]"
[Stack]: RuntimeError: unreachable
at node_modules/@as-pect/assembly/assembly/internal/assert/assert (wasm://wasm/00070616:wasm-function[64]:0x30c8)
at node_modules/@as-pect/assembly/assembly/internal/Expectation/Expectation<~lib/string/String|null>#toBe (wasm://wasm/00070616:wasm-function[129]:0xb1bb)
at start:assembly/__tests__/Token.spec~anonymous|0~anonymous|1 (wasm://wasm/00070616:wasm-function[130]:0xb392)
at export:node_modules/@as-pect/assembly/assembly/internal/call/__call (wasm://wasm/00070616:wasm-function[236]:0x14f37)
[Fail]: ✖ should get the symbol
[Actual]: "MTN"
[Expected]: "[token symbol]"
[Stack]: RuntimeError: unreachable
at node_modules/@as-pect/assembly/assembly/internal/assert/assert (wasm://wasm/00070616:wasm-function[64]:0x30c8)
at node_modules/@as-pect/assembly/assembly/internal/Expectation/Expectation<~lib/string/String|null>#toBe (wasm://wasm/00070616:wasm-function[129]:0xb1bb)
at start:assembly/__tests__/Token.spec~anonymous|0~anonymous|2 (wasm://wasm/00070616:wasm-function[131]:0xb557)
at export:node_modules/@as-pect/assembly/assembly/internal/call/__call (wasm://wasm/00070616:wasm-function[236]:0x14f37)
We now get these errors because we haven't updated the tests to reflect the changes we made to the token. Let's update the tests to reflect the changes we made to the token.
In the following code snippets the highlighted lines were added.
assembly/__tests__/Token.spec.ts | |
---|---|
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
If we run the tests again we should now have an all green 100% pass.
koinos-sdk-as-cli run-tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Result]: ✔ PASS
[Files]: 1 total
[Groups]: 2 count, 2 pass
[Tests]: 13 pass, 0 fail, 13 total
[Time]: 4944.864ms
┌───────────────────┬───────┬───────┬──────┬──────┬───────────┐
│ File │ Total │ Block │ Func │ Expr │ Uncovered │
├───────────────────┼───────┼───────┼──────┼──────┼───────────┤
│ assembly/Token.ts │ 100% │ 100% │ 100% │ 100% │ │
├───────────────────┼───────┼───────┼──────┼──────┼───────────┤
│ total │ 100% │ 100% │ 100% │ 100% │ │
└───────────────────┴───────┴───────┴──────┴──────┴───────────┘
Compiling the contract¶
We made all the necessary modifications and our tests are passing, we are now ready to build the release version of the token contract.
Let's run the build script for release.
koinos-sdk-as-cli build-all release 0 token.proto
Compiling index.ts...
node ./node_modules/assemblyscript/bin/asc assembly/index.ts --target release --use abort= --use BUILD_FOR_TESTING=0 --disable sign-extension --config asconfig.json
❯ koinos-sdk-as-cli build-all release 0 token.proto
Generating ABI file...
yarn protoc --plugin=protoc-gen-abi=./node_modules/.bin/koinos-abi-proto-gen --abi_out=abi/ assembly/proto/token.proto
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ /path/to/token/node_modules/.bin/protoc --plugin=protoc-gen-abi=./node_modules/.bin/koinos-abi-proto-gen --abi_out=abi/ assembly/proto/token.proto
installing minimist@^1.2.0
installing uglify-js@^3.7.7
installing escodegen@^1.13.0
Done in 2.25s.
Generating proto files...
yarn protoc --plugin=protoc-gen-as=./node_modules/.bin/as-proto-gen --as_out=. assembly/proto/*.proto
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ /path/to/token/node_modules/.bin/protoc --plugin=protoc-gen-as=./node_modules/.bin/as-proto-gen --as_out=. assembly/proto/token.proto
Done in 0.44s.
Generating boilerplate.ts and index.ts files...
yarn protoc --plugin=protoc-gen-as=./node_modules/.bin/koinos-as-gen --as_out=assembly/ assembly/proto/token.proto
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ /path/to/token/node_modules/.bin/protoc --plugin=protoc-gen-as=./node_modules/.bin/koinos-as-gen --as_out=assembly/ assembly/proto/token.proto
Done in 0.35s.
Compiling index.ts...
node ./node_modules/assemblyscript/bin/asc assembly/index.ts --target release --use abort= --use BUILD_FOR_TESTING=0 --disable sign-extension --config asconfig.json
After the build completes, locate your .wasm
and .abi
files:
.wasm
file:./build/release/contract.wasm
.abi
file:./abi/token.abi
With these files, we can upload our contract to the blockchain by following the Deploying a contract documentation.
Minting the token¶
Now that our contract is deployed to the testnet let's register our contract so we can mint tokens by issuing the register
command register <name:contract-name> <address:address> [abi-filename:file]
. Note that we are registering the address that we uploaded to (see above).
register test 163m4hKj1QHLCyHgnyNPw8TZU5ov25QGQX token.abi
We will get this response:
Contract 'test' at address 163m4hKj1QHLCyHgnyNPw8TZU5ov25QGQX registered
We will now have new commands available to us to interact with our contract.
To make sure it all worked we can try the command test.symbol
test.symbol
value: "MTN"
We can now issue the mint
command to mint our tokens. Let's create a new wallet we can mint the tokens to.
create mint_to.wallet password
Created and opened new wallet: mint_to.wallet
Address: 14xHsbnNnHVqDXaHq99A3ZEAEzQAwd9mtt
We need to switch back to our test.wallet
so we can mint the tokens.
test.mint 14xHsbnNnHVqDXaHq99A3ZEAEzQAwd9mtt 100000000000000
Note
Since we are using the register
command to mint the tokens, the decimals of the token are not taken into consideration. When we created out token contract we did not change the default 8 decimal places (see highlighted).
token/assembly/Token.ts | |
---|---|
13 14 15 16 17 18 19 20 21 |
|
We therefore need to enter the number of tokens to mint in the smallest unit of the token. In this case, we need to enter 100000000
to mint 1 token. Later, we will use the register_token
command which will take the decimals into account.
We should get this response:
Calling test.mint with arguments 'to: "14xHsbnNnHVqDXaHq99A3ZEAEzQAwd9mtt"
value: 100000000000000
'
Transaction with ID 0x1220e558d2d1d634321ce90e452d126a4b6b89723345b4fa9f936017770c0e28bc84 containing 1 operations submitted.
Mana cost: 0.03434252 (Disk: 95, Network: 284, Compute: 514975)
Transferring tokens¶
Let's transfer some of the tokens we just minted to a new wallet. We can use the same contract we just registered, however the CLI provides a command, register_token
that provides a cleaner interface for interacting with tokens directly.
Open the mint_to.wallet
and this time register the token contract using the register_token
command.
register_token mtn 163m4hKj1QHLCyHgnyNPw8TZU5ov25QGQX
Contract 'mtn' at address 163m4hKj1QHLCyHgnyNPw8TZU5ov25QGQX registered
We can now issue the mtn.transfer
command and transfer some tokens.
mtn.transfer 1Npov1QbcRUuw17xoWDGKEAfk2X5hJ8ueW 0.00000001
Transferring 0.00000001 MTN to 1Npov1QbcRUuw17xoWDGKEAfk2X5hJ8ueW
Transaction with ID 0x12202aa89a221ac7be8c4cbc42ff0d4cdf653a52f7b96a5824de826947684e882c37 containing 1 operations submitted.
Mana cost: 0.03231164 (Disk: 95, Network: 308, Compute: 456741)
Note
When using the register_token
command as indicated by the documentation in the Koinos CLI: Register token section, the decimals of the token are taken into consideration. As demonstrated above, we are sending 0.00000001 MTN as indicated by the 8 decimal places. If you want to use register_token
with an offline wallet, you need to provide the precision and symbol manually.
register_token mtn 163m4hKj1QHLCyHgnyNPw8TZU5ov25QGQX MTN 8
Congratulations, We successfully deployed our contract to the testnet, minted a million tokens and made a transfer! We can check the block explorer and see that we now have the newly minted tokens in our wallet and that tokens were transferred from our minted wallet.