In Focus Resource Center > Insights

How to Analyze a Smart Contract - Token Creation and Swapping

By Mark DiMichael, Karl Gutenberger .

Smart contracts are computer programs written on a blockchain that execute irreversible actions between the individual parties involved once specific terms of an agreement have been reached. Smart contracts can be faster than paper contracts, more transparent, and can remove the need for traditional intermediaries. The smart contracts can mitigate trust issues and lower the costs of these transactions. In this article, we explore how to properly analyze these types of contracts.

What is a smart contract?

Smart contracts are written by computer coders who write out the statements in the contract. When smart contracts are written, they generally utilize the statements “if/when, then” to ensure that the actions of the contract are performed correctly. The statement sets the rules of the contract, and more layers can be added as needed. There are many computer programming languages that can code smart contracts. One of the most widely use programs is Solidity for the Ethereum blockchain. However, it is not necessary to know how to write computer code in order to read/use smart contracts.

Let’s run through an example of a smart contract and how it can be useful. In this example, a company is raising capital by issuing a cryptocurrency unit as an ownership unit rather than a stock certificate. The smart contract can automatically issue tokens when the investors have paid and/or met other criteria specified by the smart contract’s computer code. Or, if the company fails to raise enough capital, the smart contract can return the funds to the investors. The need for a broker, bank, or transaction clearing house is effectively eliminated and replaced by computer code.

New tokens are added to the blockchain from an account referred to as a “null address”. When a company is raising capital, the investors will need to send their funds to the smart contract, which will then provide them with new tokens from the null address. From there, the investor can trade their new tokens just like any other cryptocurrency.

The benefits of using smart contracts

Smart contracts can be executed quicker than the manual process of signing a physical contract. Smart contract creators can add any requirements and/or conditions they desire into the smart contract code. In the example above, if all investors contributed capital to the smart contract for new shares of stock or tokens and the contract order has been fulfilled, the transaction will automatically execute. This eliminates the need for all parties to physically obtain the contract or utilize an electronic signature program such as DocuSign prior to the capital being released.

These self-executing contracts can increase the level of trust for all parties involved. Since there are no third-party intermediaries, there is less room for human error. The contract execution is based off computer code which is publicly recorded on a blockchain. As these smart contracts are open source, anyone can view the code details and blockchain encryption makes the system very secure.

Smart contracts can also reduce costs. All parties can directly send and receive currencies or tokens to each other without having to pay intermediaries fees or wait for paperwork/filing to be completed prior to execution. Since everything is digital, the elimination of mail, physical ledgers or records can result in less environmental waste. The offsetting environmental considerations can vary depending on many factors including which blockchain is used.

Deciphering a smart contract

An individual can see the transaction record for a smart contract that occurred on the blockchain by looking at a block explorer. In the figures below, we discuss the information available for smart contracts on the Ethereum Blockchain as shown on numerous websites such as www.etherscan.io. An individual can generally decipher the substance of the transaction by looking at the information in a particular transaction hash.

A good place to start when looking at a smart contract transaction is the transactions overview page. Here you will see a summary of the contract’s information such as the hash (or transaction ID), transaction action, the ‘To’ address (contract’s address) and ‘From’ address (individual who initiated the transaction and directed the contract to carry out an action) of those entering the contract, the balance (ETH) and its value (USD), and fees (ETH) with some other miscellaneous bits of additional information.

General terminology and information

The ‘From’ address is the individual/company that initiated the transaction and requested the contract perform an action. The ‘To’ address represents the smart contracts address where investors from the above example will need to send capital in exchange for cryptocurrency units. The transaction action is a high-level description of transaction’s impact overall.

When clicking into the contract’s address, the transaction section of Etherscan.io provides greater detail as to the contract’s past activity. Under ‘More info’ you can find the contract creator’s address. The contract’s address and the contract creator’s address will generally be different than individual's address who is executing the smart contract (the “From” address discussed above).

There are many transaction types that can be executed by smart contracts, such as contract creations, entering and exiting liquidity pools, swapping tokens, wrapping tokens, minting NFTs, purchasing/selling NFTs, and airdrops. Below, we will discuss two types of smart contract transactions; creating a smart contract, and how someone might swap tokens below.

smart contract figure 1

Figure 1 - Creating a smart contract:
Figure 1 (https://etherscan.io/tx/0x6b48823a48ff1eedba0a2f557b4a35361cf460bc211e29d1d0fd926a9f58f78d)

Figure 1 above shows the creation of a smart contract. The ‘From’ line shows the address of the person who initiated this first transaction, ‘0x50bd9’. The “Interacted With (To)” line items shows that smart contract ‘0xde955’ (only listing the first seven digits for readability) was just “created”. The next line down shows that address ‘0x50bd9’ received 400,000 new “KJV” tokens which came from the “Null Address”. Since these tokens are coming from the “Null Address” to ‘0x50bd9’ we know these are newly created tokens that did not previously exist. The “Value” line-item shows ($0.00) ETH, which means that no ETH tokens were transferred as part of this transaction.

The next line, Transaction Fee, however, shows 0.0829 ETH worth at $155.85 USD was paid as a transaction processing or “gas fee” for creating these tokens. To summarize using my example from earlier, Company A or ‘0x50bd9’ created 400,000 new “KJV” tokens and issued them all to themselves and could re-sell the “KJV” tokens to others in the future. A smart contract is the only way to issue new tokens on the Ethereum blockchain.

smart contract figure 2

Figure 2 - Swapping tokens using a smart contract:
Figure 2 (https://etherscan.io/tx/0x323b0f4e96abec8a16c924d62ca5d614271e71231406af14df293abd1a75b66c)

The next instance in figure 2 shows how someone can swap tokens using a smart contract. Swapping tokens is exactly what it sounds like, exchanging one set of tokens for another. Uniswap is a collection of smart contracts that are referred to as “liquidity pools”. Liquidity pools act as cryptocurrency brokers that trade with individuals, just like a stockbroker would. In this particular example, ‘0x68b34’ (only listing the first seven digits for readability) traded 0.04 ETH tokens for 1,836,952 VISA tokens. Let’s assume the 0x68b34 address is owed by John (we’ll refer to that address as John going forward).

smart contract figure 3

Computer programs that execute these types of transactions are generally designed to act efficiently, which means obtaining the best price, with the lowest possible transaction processing fees. Computer programs called “Routers” make this happen. In this particular case, the Uniswap router executed multiple transactions to make this trade. In this case the router took John’s ETH, traded it for Wrapped ETH tokens (WETH), and then traded the WETH for Visa tokens. See flow chart below:

The ‘From’ line shows John’s address (the person who initiated this first transaction, ‘0xe9eb4’).

The “Interacted With (To)” line items show the smart contract that John called – the Uniswap V3: Router 2 smart contract address ‘0x68b34’ (only listing the first seven digits for readability). The second line item shows Uniswap sending John’s 0.04 ETH to the WETH smart contract.

The “Tokens Transferred” line shows two items:

  1. 0.04 WETH send to another liquidity pool
  2. 1,836,951.6668 “VISA” tokens (rounded) sent from Uniswap to John.

The “Value” line-item shows the original 0.04 ETH that John sent to make the trade. A note to point out is that this contract was on Uniswap (Liquidity pool provider) and had already existed since we do not see “Null Address” anywhere in that transaction. In addition to paying 0.04 ETH, John had to pay a transaction fee of .007341 ETH (rounded) to process the swap. Using smart contracts to swap one token for another is an advantage to the cryptocurrency trader. While swapping one stock for another is very rare, swapping one token for another is common, without having to convert back to USD prior to swapping.

Drawbacks of smart contracts

There can be drawbacks to smart contracts as well. As smart contracts are built from computer code, there can be problems if the code was written incorrectly. Additionally, the concept of a smart contract may be difficult to understand for the average individual or investor. However, the automation benefits and costs savings can be significant as smart contract usage continues to evolve. Reading computer code can be complex and difficult to analyze, but one does not need to understand how the computer code is written to understand the flow of the transactions. By focusing on the parties (addresses) involved and token movement in a transaction, we can begin to understand its substance.

For more information, please reach out to Karl Gutenberger at kgutenberger@citrincooperman.com or Mark DiMichael at mdimichael@citrincooperman.com.

Our specialists are here to help.

Get in touch with a specialist in your industry today. 

* Required

* I understand and agree to Citrin Cooperman’s Privacy Notice, which governs how Citrin Cooperman collects, uses, and shares my personal information. This includes my right to unsubscribe from marketing emails and further manage my Privacy Choices at any time. If you are a California Resident, please refer to our California Notice at Collection. If you have questions regarding our use of your personal data/information, please send an e-mail to privacy@citrincooperman.com.