China Protest Beijing Demonstrator Sparks

Welcome to Articlesworlds.com. Today’s Topic is About China Protest Beijing Demonstrator Sparks as you know from the article’s title. Make sure to become a part of our website by sharing your…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Transferring ERC20 tokens across accounts

I have been going through a couple of frustrating weeks trying to create simple workflows that help transfer ERC20 tokens to merchants to process payments from customers. There aren’t enough structured ‘help repositories’ to enable budding programmers to get the job done quickly. I thought of creating this article to help folks who are trying to figure out which methods to use for this workflow.

One of the first things I learnt is that the ERC20 contract is the main holder of all sums and balances. Customers and merchants who deals with a virtual token of a particular type have their ownership information registered with the contract. This means that transferring tokens to anyone other than the contract itself simply modifies ‘account balance’ values via the contract for the sender and the receiver. Any entity that wishes to know their account details need to call the contract methods to get them using balanceOf().

Let’s say one entity wishes to transfer tokens to another entity (a customer wants to pay tokens to a merchant for a purchase, for instance), you can use the sendSignedTransaction call to achieve this. Here is an excerpt:

Few key elements in the code need to be noted…

We are transferring from ‘fromAcct’ to ‘toAcct’ a value of ‘amount’. To enable this, we create a raw transaction.

The ‘to’ field refers to the address of the deployed contract that we are requesting to execute the token transfer. This is different from the ‘toAcct’ who is the payee.

The ‘data’ field refers to the method call we request the contract to execute i.e. the ‘transfer’ method in the contract with explicit arguments encoded as ‘toAcct’, and the ‘amount’ to be transferred to ‘toAcct’.

Next we sign the transaction using the private key of the payer, which is analogous to getting the payer’s approval to transfer money from the payer’s account to payee’s.

Finally, this is followed by a call to the sendSignedTransaction to execute the call.

This was tested with a private quorum network. Testbed info:

Hope this helps.

Add a comment

Related posts:

New Pioneers coach preaches peace at practice

Sytsma is the new football coach at Frankford High School, and Pastore is the head man at Boys Latin. The coaches are competitors and new Thanksgiving rivals on the football field, but they want the…

The Sound of Things to Come and the Smallness of the World

There is a saying that the world is a small place, that there is always someone who knows someone who knows us. Ours, we have come to believe, is a far-flung, yet close by neighborhood. In The Sound…

Share

Thank you for taking the time to read my work. I know there are many pieces dividing your time, energy, and focus as you navigate our medium community. In a previous piece, I suggested you read more…