# ERC20

## Querying

* Let's work with ERC20 tokens with Blueprint!
* Back to the map, select the drop down menu of **Blueprints** > **Open Level Blueprint** and launch the Level Blueprint Editor

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-1776cc35b25c08383d9ceaec2caac50a23917708%2Fimage%20(5)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* The following screenshot shows Query the name of ERC20 contract and print it on the screen. In this example, we use a Function - **Spawn Actor from Class** to create an Actor instance from **BP\_DefiWalletCore** Class. The Transformation defines the location, rotation, and scale that will be used by the new Actor. A reference to the new instance is available in the Return Value which feeds as input Value of Function **Erc20Name. Erc20Name** also has an input **Contract Address**, for example, we set it as **0xf0307093f23311FE6776a7742dB619EB3df62969**. Finally, print the token name with Function - **Print String**.

  <figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-f0a0a443efbd999be6e12140a0967915b142568e%2Fimage%20(17)%20(1).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>
* Click **Compile** > **Play**, **USDC** is printed in the game.
* We can create a variable **contract** and set the default value as **0xf0307093f23311FE6776a7742dB619EB3df62969** for later easy access.

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-e5b2ee760521f15a8dd4af6c1c6f6c869a0548c6%2Fimage%20(19)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

* Similarly, we can call other ERC20 functions by dragging from the **Return Value** of the **SpawnActor BP Defi Wallet Core** and search to add **Erc20Balance**, **Erc20Symbol**, **Erc20Decimals**, and **Erc20TotalSupply** like below

  <figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-0ca59d003ad1d67867bab9011e7c2efcf43789dd%2Fimage%20(16)%20(1).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

  PS: In above example, we use Account Address **0xf0307093f23311FE6776a7742dB619EB3df62969** to query its balance.

## Functions

All ERC20 functions are members of **DefiWalletCoreActor**. The Target should be **Defi Wallet Core Actor**.

### Erc20Balance

Get erc-20 balance

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-cbf256c2bfb908a8d7a1fe425ffad4e488e11304%2Fimage%20(6)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract address
* `Account Address`: account address to fetch balance
* `Balance`: get balance of account address
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed

### Erc20Name

Get erc-20 name

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-6183ac07054fb84544f6d38e2127e0bf4a2716e8%2Fimage%20(5)%20(3)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract address
* `Name`: get name
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed

### Erc20Symbol

Get erc-20 symbol

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-3aba978139e0ee7afaa476750d9019a9fff5c698%2Fimage%20(1)%20(3).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract address
* `Symbol`:: get symbol
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed

### Erc20Decimals

Get erc-20 decimals

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-f5265a4e47a9710cf4a031e8f928a8253175bfaf%2Fimage%20(10)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract address
* `Decimals`: get decimals
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed

### Erc20TotalSupply

Get erc-20 total supply

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-03092b651e3e2466689c667996cb30ebbe93443a%2Fimage%20(4)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract address
* `Total Supply`: get total supply
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed

### Erc20Transfer

erc20 Moves `amount` tokens from the caller’s account to `to_address`.

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-766b56ebc01b52a09020ea1503ef4060b41b52f8%2Fimage%20(8)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract
* `Walletindex`: wallet index which starts from 0
* `To Address`: to address
* `Amount`: amount
* `Out`: Erc20Transfer callback

### Erc20TransferFrom

erc20 Moves `amount` tokens from `from_address` to `to_address` using the allowance mechanism.

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-1cdf68bb76c34063c63a75f4c17444b9b0b85a31%2Fimage%20(3)%20(2)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract
* `Walletindex`: wallet index which starts from 0
* `From Address`: from address to move
* `To Address`: to address
* `Amount`: amount
* `Out`: Erc20TransferFrom callback

### Erc20Approve

erc20 Allows `approved_address` to withdraw from your account multiple times, up to the `amount` amount.

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-0b70b9d6c00d08aa1d1d40fdd3a1b1c8ffe48b86%2Fimage%20(11)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract
* `Walletindex`: wallet index which starts from 0
* `Approved Address`: address to approve
* `Amount`: amount
* `Out`: Erc20Approve callback

### Erc20Allowance

Returns the amount of tokens in existence

<figure><img src="https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-c3b776bc5377cac9ef1789a72acc9df469015c63%2Fimage%20(9)%20(2).png?alt=media" alt=""><figcaption></figcaption></figure>

* `Contract Address`: erc20 contract
* `Erc 20owner`: erc20 owner
* `Erc 20spender`: erc20 spender
* `Result`: allowance
* `Success`: whether succeed or not
* `Output message`: error message, "" if succeed
