Querying a contract

After creating MyDefiWalletCoreActor, we can switch to the source code editor and add token querying feature in the actor.

AddingPlayCppSdkLibrary as dependency module

  • Edit CronosPlayDemo.Build.cs, and add PlayCppSdkLibrary, as one of the Dependency Modules.

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "PlayCppSdkLibrary" });

Querying the name of a ERC20 contract

  • Create constructor, and two overridden functions: BeginPlay and Tick

  • In BeginPlay function, call Erc20Namefunction from ADefiWalletCoreActor, and print out logs like below

bool success;
FString output_message;
ADefiWalletCoreActor::Erc20Name("0xf0307093f23311FE6776a7742dB619EB3df62969", name, success, output_message);
FString success_message = success ? "true" : "false";
UE_LOG(LogTemp, Display, TEXT("ERC20 name: %s"), *name);
UE_LOG(LogTemp, Display, TEXT("ERC20 success: %s"), *success_message);
UE_LOG(LogTemp, Display, TEXT("ERC20 output_message: %s"), *output_message);

Examples

MyDefiWalletCoreActor.h

MyDefiWalletCoreActor.cpp

Building

Select Development Editor Profile in tool bar > Build > Build Solution (Disable Live Coding on Unreal Editor before building)

Last updated

Was this helpful?