Why It’s Difficult to Receive Payments via Ethereum Smart Contracts

Park Juhyung
CodeChain
Published in
4 min readJun 27, 2019
Photo by JESHOOTS.COM on Unsplash

What differentiates Ethereum is that it is possible to create a variety of applications on blockchains using smart contracts. However, at times, smart contracts make simple tasks more difficult than they have to be. For example, it is very difficult to find out how much ETH was deposited at a certain address in Ethereum. This is because there is no way to know what a smart contract actually does without running it.

Why the Internals and Externals of Blockchains Must be Synced

The smart contract only reads and writes the data stored in the blockchain. You can create useful applications by only using blockchain data. Multi-signature wallets and smart contracts such as ERC-20 and ERC-721 tokens are useful applications for reading and writing data stored in blockchains. Most applications, however, must be connected to the externals of the chain.

An example is the exchange. An exchange can take ETH and convert it to cash or purchase ETH with cash. After confirming the payment received from the chain, it sends money to the account of the bank or, conversely, check the money received in the account and send ETH.

Even though it could be a task that could be done with smart contracts, it may be better to do it externally from the chain because smart contracts are expensive. Smart contract calls are calculated by all the nodes in the network. As of June 2019, approximately 8,000 nodes participate in the Ethereum network. This means that once you call a smart contract once, it will run 8,000 times. Thus, tasks like this are better to be done outside of the chain to save some cash.

However, connecting the internals and externals of the chain is not as easy as it sounds.

How to Read How Much ETH a Specific Account Holds

Occasionally, there are exchanges that prohibit the use of smart contract wallets when depositing ETH. Most exchanges will create unique Ethereum addresses for each user, and they will check if the user deposits ETH at that address. It’s easy to check the ETH in an account, but why would they refuse deposits with the smart contract?

There are two types of transactions where ETH is deposited into a specific account. Firstly, there are transactions that send ETH to other accounts, and secondly, there are transactions that call smart contracts. Transactions that send ETH can read From, To, and Value that are written in the transaction, so that it is easy to see who sends what. This is usually the easiest way to check the balance. On the other hand, transactions that call smart contracts have no way of knowing how much money they have put into which account. It is not listed in the transaction information, and there is no API in the Ethereum SDK to fetch the information.

There are three ways to solve this problem.

The easiest way to do this is to ask the user to make a direct deposit, and not to accept payment via smart contracts. The early exchanges operated in this manner, and there are still quite a few exchanges that only process money that have been deposited directly.

(The Huobi Exchange does not accept smart contract deposits.)

Another way is to check your account balance at every block. The difference between the balance calculated in the previous block and the balance calculated in the current block is the amount of ETH that has been deposited. However, it is difficult to trace the transaction because it is not possible to know in which transaction the amount came in. Furthermore, since it is necessary to check the balance of all accounts managed for each block, this method also has a disadvantage when it comes to time efficiency.

Another way is to use the trace API provided by the Go Ethereum (link) and Parity (link) implementations. Each implementation provides an API that keeps track of what the transaction in the block has done in detail in its own way. Using the trace API, you can see which state each transaction modified in EVM instruction units. In this way, you can track how much money a smart contract has deposited into an account. The disadvantage is that the use of the API is complex and must be running a full node. Also, since it is not an official API, it can be changed according to implementation.

Conclusion

So far, there have been three ways to find out how much money has been deposited into a specific account when using smart contracts in Ethereum. Information that reveals who put in how much in my account at what time is a very basic piece of data, but there is no easy and perfect method to retrieve it. In each application, you can choose the method that meets your requirements.

--

--