NEO blockchain, programming tutorials, Javascript — 4

館長
Blockchain Under The Hood
2 min readMay 20, 2018

NEP5 Token Transfer

neon-js

This is a series of how you can start to build a decentralized app on the top of NEO. Before moving forward, I will guide you the fundamental aspect before we get started.

I am a full-stack javascript developer and one of the contributors for NEO blockchain project.

How To Get Started

NEO blockchain, programming tutorials, Javascript — 1

Transfer NEP5 Token

Goal: Transfer 22.22 ONT

const NEON = require('@cityofzion/neon-js')
const { api, wallet, u } = NEON
const account = new wallet.Account(**privateKey**)
const toAddress = 'AWXWmwm3UCXeDcLM8RpF7QLdsMrnrbHNxj'
const ontTokenScriptHash = 'ceab719b8baa2310f232ee0d277c061704541cfb'
const ontTransferAmount = 100.001Neon.api.doInvoke({
net: 'MainNet',
account: account,
intents: api.makeIntent({ GAS: 0.00000001 }, account.address),
script: {
scriptHash: ontTokenScriptHash,
operation: 'transfer',
args: [
u.reverseHex(wallet.getScriptHashFromAddress(account.address)),
u.reverseHex(wallet.getScriptHashFromAddress(toAddress)),
new u.Fixed8(ontTransferAmount).toReverseHex(),
],
},
})
.then(response => {
...update ui accordingly
})

Tip of the day

doInvoke under the hood is actually doing lots of things for you in order to communicate with rpc .

  • Step 1
    fillUrl — With provided net , it would help you to decide the best rpc among all the available rpcs
  • Step 2
    fillKeys — With provided account , it would help you out to fill out keys of address, privateKey and publicKey
  • Step 3
    fillBalance — With provided account , it has the ability the abstract address from it. Then it would use API call to get your balance.
  • Step 4
    createTx — Create a transaction invocation, and check all the necessary fields are provided before using your privateKey to sign it
  • Step 5
    signTx — Sign the invocation that was created with your privateKey

I have intentionally leak out some information that I think it not necessary for transfer nep5 token. Feel free to check out their source code for more information.

Stay Tune

For coming Monday topic, I will look at the response message and see which one that might fit for the coming topic. Feel free to drop message to me if you want to suggest a topic for me.

I make one post on every Monday UTC+0 time zone, but if I have more than 500 claps, I make another post immediately.

Useful Link

Blockchain Programing
1.「NEO blockchain, programming tutorials, Javascript — 1
2.「NEO blockchain, programming tutorials, Javascript — 2
3.「NEO blockchain, programming tutorials, Javascript — 3
4.「NEO blockchain, programming tutorials, Javascript — 4
5.「NEO blockchain, programming tutorials, Javascript — 5

NEP5 Token ScriptHash List
NEP5 token scriptHash

What Is Ontology?
What is Ontology? (Programmer Explain) / 什麼是 Ontology? 聽聽工程師怎麼說

Github
My Github

Neon-JS
NEON-JS-SDK

Blockchain Link List
Blockchain Posts List

About me
I am a full-stack javascript developer and one of the contributors for NEO blockchain project.

Build Decentralized Application with Javascript on the top of NEO?
NEO blockchain, programming tutorials, Javascript

If you consider yourself a talent?
Cobinhood Careers

--

--

Blockchain Under The Hood
Blockchain Under The Hood

Published in Blockchain Under The Hood

A full stack javascript developer will bring you what is happening for blockchain under the hood

館長
館長

Written by 館長

Lead of Product & Engineering, DApps Developer.