In last post we discussed about ERC20 token: https://fifo.im/p/ttipy8x99xw0
In this post, we’ll explore how to use truffle-token-test-utils package to visualize token transfers in Truffle and OpenZeppelin tests.
When we do transactions on the Ethereum blockchain, one can easily view the internal token transfers that took place by looking it up on Etherscan as shown above.
While testing contracts on local ganache or forked mainnet, it can be a black box as you only have the ability to check token balances before and after the transaction.
To make it easier to achieve a similar result as Etherscan, we’ll use my npm package: `truffle-token-test-utils`.
Here’s the terminal’s output which we’ll achieve in the end:
Install the package in your truffle project
npm install truffle-token-test-utils
Import the package in your test file
const tokenTransfers = require("truffle-token-test-utils");
Initialize the tokenTransfers
object like this:
contract("ContractName", (accounts) => {
tokenTransfers.setWeb3(web3);
...
}
Here the web3
object gets auto injected by truffle during test execution.
Inside the it block for your test case, as you call the contract function, store it in tx variable and just print the token transfers in the console:
const tx = await someContract.someFunction();
await tokenTransfers.print(tx);
That’s it! Run the test and visualize token transactions!
Hello Everyone, In recent years, Docker has revolutionized the way we develop, deploy, and manage software applications. With its lightweight and portable containerization technology, it enables developers to package their applications along with all their dependencies into a single unit, making it easier to run across different environments. This post will provide an overview of the concepts and components of Docker, helping you grasp the fundamentals of this powerful tool.
What are Webhooks? The ability of independent online systems to communicate with one another and share data is the core of what makes online services valuable today. In this post, will look at webhooks.