Skip to main content

02 Sending transactions & retrieving data

This page lists the different methods you can use in your game.

in general

All write method calls such as minting a character or wearable incur gas fees to cover smart contract operations. Tickets are issued for these and approval needed via MetaMask.

All read data method calls such as retrieving a balance do NOT incur gas fees.

🕹  Guided tutorial

Send transaction


The SendTransaction function interacts with the blockchain and incurs gas fees. Signing in MetaMask is required. When a call is made, the back end client sends a 'Ticket' in MetaMask if the call was successful.

URL

http://45.77.189.28:5000/send/transaction

Parameters

device_id, contract_address, abi_hash, method, args

Response

A ticket is the response.

The session saved during the GetClientcall is used to open MetaMask. MetaMask will popup to display gas fees for the transaction. Sign or confirm the transaction for that ticket.


void UAnkrClient::SendTransaction(FString contract, FString abi_hash, FString method, FString args, FAnkrTicket Ticket)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Ticket, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
FString data = Response->GetContentAsString();

if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
FString ticketId = JsonObject->GetStringField("ticket");
data = ticketId;
}

Ticket.ExecuteIfBound(data);
});

AsyncTask(ENamedThreads::AnyBackgroundThreadNormalTask, [this, Request, contract, abi_hash, method, args]()
{
FString url = baseUrl + "send/transaction";

Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetContentAsString("{\"device_id\": \"" + deviceId + "\", \"contract_address\": \"" + contract + "\", \"abi_hash\": \"" + abi_hash + "\", \"method\": \"" + method + "\", \"args\": \"" + args + "\"}");
Request->ProcessRequest();
});
#if PLATFORM_ANDROID
FPlatformProcess::LaunchURL(session.GetCharArray().GetData(), NULL, NULL);
#endif
}

Checking status of ticket


Check status of tickets by calling GetTicketResult.

For example, if you come back to the game, check the status of the ticket with GetTicketResult having body parameters as device_id, ticket.

Returns the status of the result.

URL

http://45.77.189.28:5000/send/GetTicketResult

Parameters

device_id, ticket

Response

Successful or Unsuccessful.

Get Data


GetData is used to retrieve data associated with a particular wallet and user from a contract.

URL

http://45.77.189.28:5000/wallet/call/method

Parameters

device_id, contract_address, abi_hash, method, args

Response

The data for a particular wallet and user from a contract is returned.

void UAnkrClient::GetData(FString contract, FString abi_hash, FString method, FString args, FAnkrDelegate Result)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Result, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
Result.ExecuteIfBound(Response->GetContentAsString());
});

FString url = baseUrl + "call/method";

Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetContentAsString("{\"device_id\": \"" + deviceId + "\", \"contract_address\": \"" + contract + "\", \"abi_hash\": \"" + abi_hash + "\", \"method\": \"" + method + "\", \"args\": \"" + args + "\"}");
Request->ProcessRequest();
}

Send ABI


SendABI is used to send a request and retrieve the ABI hash generated by the backend.

URL

http://45.77.189.28:5000/abi

Parameters

abi

Response

The ABI hash is returned.


void UAnkrClient::SendABI(FString abi, FAnkrDelegate Result)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Result, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
FString data = Response->GetContentAsString();

if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
Result.ExecuteIfBound(JsonObject->GetStringField("abi"));
}
});

FString url = baseUrl + "abi";

Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));

const TCHAR* find = TEXT("\"");
const TCHAR* replace = TEXT("\\\"");
FString body = FString("{\"abi\": \"" + abi.Replace(find, replace, ESearchCase::IgnoreCase) + "\"}");

Request->SetContentAsString(*body);
Request->ProcessRequest();
}

Sign message


SignMessage is used to send a request that requires confirmation in MetaMask. The session saved during GetClient will be used to open MetaMask.

URL

http://45.77.189.28:5000/sign/message

Parameters

device_id, message

Response

A ticketid is returned.


void UAnkrClient::SignMessage(FString message, FAnkrDelegate Result)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Result, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
FString ticketId = JsonObject->GetStringField("ticket");

#if PLATFORM_ANDROID
FPlatformProcess::LaunchURL(session.GetCharArray().GetData(), NULL, NULL);
#endif
Result.ExecuteIfBound(ticketId);
}
});

FString url = baseUrl + "sign/message";

Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetContentAsString("{\"device_id\": \"" + deviceId + "\", \"message\":\"" + message + "\"}"); // erc20 abi
Request->ProcessRequest();
}

The Call is as follows:


FString url = baseUrl + "sign/message";

Get signature


GetSignature is used to verify a message by getting a signature data object.

URL

http://45.77.189.28:5000/result

Parameters

device_id, ticket

Response

A 'data' object with 'signature' string field.


void UAnkrClient::GetSignature(FString ticket, FAnkrDelegate Result)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Result, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
TSharedPtr<FJsonObject> data = JsonObject->GetObjectField("data");
Result.ExecuteIfBound(data->GetStringField("signature"));
}
});

FString url = baseUrl + "result";

Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetContentAsString("{\"device_id\": \"" + deviceId + "\", \"ticket\":\"" + ticket + "\"}");
Request->ProcessRequest();
}

Verify message


VerifyMessage is used to verify a signature and connect a player account with a connected wallet's public address.

URL

http://45.77.189.28:5000/verify/message

Parameters

device_id, message, signature

Response

Account 'address'. The account address for the connected wallet's public address.


void UAnkrClient::VerifyMessage(FString message, FString signature, FAnkrDelegate Result)
{
http = &FHttpModule::Get();

TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = http->CreateRequest();
Request->OnProcessRequestComplete().BindLambda([Result, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
Result.ExecuteIfBound(JsonObject->GetStringField("address"));
}
});

FString url = baseUrl + "verify/message";
Request->SetURL(url);
Request->SetVerb("POST");
Request->SetHeader(TEXT("User-Agent"), "X-MirageSDK-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->SetContentAsString("{\"device_id\": \"" + deviceId + "\", \"message\":\"" + message + "\", \"signature\":\"" + signature + "\"}");
Request->ProcessRequest();
}