- 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
-
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.
-
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.
-
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
PS: In above example, we use Account Address 0xf0307093f23311FE6776a7742dB619EB3df62969 to query its balance.
All ERC20 functions are members of DefiWalletCoreActor. The Target should be Defi Wallet Core Actor.
Get erc-20 balance
Contract Address
: erc20 contract addressAccount Address
: account address to fetch balanceBalance
: get balance of account addressSuccess
: whether succeed or notOutput message
: error message, "" if succeed
Get erc-20 name
Contract Address
: erc20 contract addressName
: get nameSuccess
: whether succeed or notOutput message
: error message, "" if succeed
Get erc-20 symbol
Contract Address
: erc20 contract addressSymbol
:: get symbolSuccess
: whether succeed or notOutput message
: error message, "" if succeed
Get erc-20 decimals
Contract Address
: erc20 contract addressDecimals
: get decimalsSuccess
: whether succeed or notOutput message
: error message, "" if succeed
Get erc-20 total supply
Contract Address
: erc20 contract addressTotal Supply
: get total supplySuccess
: whether succeed or notOutput message
: error message, "" if succeed
erc20 Moves amount
tokens from the caller’s account to to_address
.
Contract Address
: erc20 contractWalletindex
: wallet index which starts from 0To Address
: to addressAmount
: amountOut
: Erc20Transfer callback
erc20 Moves amount
tokens from from_address
to to_address
using the allowance mechanism.
Contract Address
: erc20 contractWalletindex
: wallet index which starts from 0From Address
: from address to moveTo Address
: to addressAmount
: amountOut
: Erc20TransferFrom callback
erc20 Allows approved_address
to withdraw from your account multiple times, up to the amount
amount.
Contract Address
: erc20 contractWalletindex
: wallet index which starts from 0Approved Address
: address to approveAmount
: amountOut
: Erc20Approve callback
Returns the amount of tokens in existence
Contract Address
: erc20 contractErc 20owner
: erc20 ownerErc 20spender
: erc20 spenderResult
: allowanceSuccess
: whether succeed or notOutput message
: error message, "" if succeed