Table of contents
2 min read
Sending EOS and Tokens with eosjs (2/2): Token transfer
Use the eosjs transaction method to send tokens that live in custom contracts on EOS.
The previous post used eosjs’s transfer method to send the native EOS coin. Any “action” on EOS — transfer included — needs two pieces of information:
- The contract account name (for EOS coin:
eosio.token) - The action name defined on that contract (for EOS coin:
transfer)
The transfer method we used in the previous post bakes these two values in for you. It’s a convenience that makes sense given EOS is the chain’s native currency and the most-transferred asset.
Tokens are a different story. eosjs has no way to know which contract account a given token lives on, and that contract’s transfer action might not even be named transfer. For those cases, eosjs exposes the lower-level transaction method.
The transaction method
Here’s what a token transfer looks like via transaction. The example uses await so the result is bound to a result variable:
let result = await eos.transaction({
actions: [{
account: "lioncontract",
name: "transfer",
data: {
from: "lazylion1234",
to: "babylion1234",
quantity: "12.0000 LION",
memo: "eosjs is quite easy to use!!"
},
authorization: [{
actor: "lazylion1234",
permission: "active"
}]
}]
});
console.log(result.transaction_id); // print the resulting transaction idactions: the list of actions to perform. A single transfer action is the typical case for sending a token. The example fires thetransferaction on thelioncontractcontract.actions → account: the contract’s account name.actions → name: the action name defined on the contract.actions → data: the payload the action expects. Note thatlioncontract’s transfer takes the same fields as the native EOS transfer.actions → authorization: the permission used to sign this action. Since the sender islazylion1234, the call needs that account’sactivepermission.
Inspecting the transaction log
Here’s what calling transaction logs:

eosjs fetches the contract’s ABI, retrieves the current block info, builds the matching transaction, signs it, and pushes it.
That wraps up coin and token transfers with eosjs. The hard parts — assembling the right RPC sequence, signing, broadcasting — collapse into a single call.
In This Series
Sending EOS and Tokens with eosjs
2 / 2
Keep Reading
- Building EOS Web Apps with Scatter (2/2): Transactions and sign-out
Use a Scatter-bound EOS account to send coins, transfer custom tokens, vote for block producers, and sign out — without ever embedding a private key in your code.
Development · 2018-11-14
- Building EOS Web Apps with Scatter (1/2): Account binding
Use Scatter, a Chrome-extension key manager, to bind an EOS account to a web service without ever exposing the private key in the browser.
Development · 2018-10-19
- Ethereum vs EOS: Who Wins?
A side-by-side look at Ethereum (gen 2) and EOS (gen 3) across usability, fees, and dApp adoption — and a guess at which platform might lead next.
Development · 2018-12-06
Discussion