Skip to content

Simplifying Smart Contract Interaction

The Eidolon Transaction Builder is a remarkable tool that simplifies the process of generating code for interacting with smart contracts in your Eidolon project. It streamlines the development workflow and allows developers to focus on building blockchain-powered features without the complexity of writing contract interaction code manually. Let’s explore the capabilities and ease of use of this tool, along with an example.

Transaction Builder

Overview of the Transaction Builder

The Eidolon Transaction Builder is designed to generate C# scripts that facilitate interactions with smart contracts. It provides the following key features:

1. Contract Method Extraction

  • Parses the ABI (Application Binary Interface) of a smart contract, which is essential for understanding how to interact with its methods.
  • Allows you to select a specific method from the contract’s ABI for which you want to generate interaction code.

2. Code Generation

  • Generates C# scripts tailored to the selected method, simplifying the process of interacting with the smart contract.
  • Distinguishes between read and write methods, providing the appropriate code generation for each.

3. User-Friendly Interface

  • Provides a user-friendly graphical interface within the Unity Editor for inputting contract details and generating code.

Now, let’s delve into how amazing and easy it is to use the Eidolon Transaction Builder.

How to Use the Eidolon Transaction Builder

1. Opening the Transaction Builder

To access the Transaction Builder, follow these steps:

  1. Launch the Unity Editor.

  2. Navigate to the Eidolon menu.

  3. Select Transaction Builder.

Alternatively if you already have a contract under My Contracts, you can:

  1. Go to My Contracts -> Manage Contracts.
  2. Choose the contract you want to build a transaction for.
  3. Click on Transaction Builder

2. Inputting Contract ABI

  • Paste the ABI of your smart contract into the Enter Contract ABI text area.

  • Click the Extract Methods button to parse the ABI and identify its methods.

3. Selecting a Method

  • Choose the method you want to generate code for from the dropdown list of available methods.

4. Providing Contract Address and Script Name

  • Enter the contract address you want to interact with in the Enter Contract Address field.

  • Specify a script name for the generated code in the Enter Script Name field.

6. Code Generation

  • Click the Generate Code button to generate C# code for the selected method.

7. Integration

  • The generated code can be easily integrated into your Eidolon project and used to interact with the smart contract.

Example: Generating Code for a Transfer Method

Let’s demonstrate the use of the Transaction Builder by generating code for a hypothetical Transfer method of an ERC-20 token contract.

  1. Open the Transaction Builder and input the ABI of the ERC-20 token contract.

  2. Click Extract Methods to identify available methods.

  3. Choose the Transfer method from the list.

  4. Enter the contract address and script name.

  5. Click Generate Code to generate the script.

The generated script might look like this for WebGL games:

using Nethereum.Util;
using Nethereum.Web3;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
public class TokenTransferScript : MonoBehaviour
{
static WebGLWallet wallet;
static SmartContract ContractName;
private void Awake()
{
Wallet = new WebGLWallet();
ContractName = new SmartContract("ContractAddressHere", "ABIHere", wallet);
}
// Your generated function. Feel free to rename variables or add to this script.
// This function can be invoked from other scripts with TokenTransferScript.Transfer(string recipient, BigInteger amount).
public static async void Transfer(string recipient, BigInteger amount)
{
// Contract Method
string methodName = "transfer";
// Method Arguments
object[] arguments = new object[]
{
recipient,
amount
};
try
{
// Send the transaction by passing only the method and parameters.
var transactionHash = await ContractName.SendTransaction(methodName, parameters: arguments);
Debug.Log("Transaction Hash: " + transactionHash);
}
catch (System.Exception e)
{
Debug.Log(e);
}
}
}

With this generated code, developers can easily perform token transfers within their Eidolon project without needing to manually write complex contract interaction code.

Conclusion

The Eidolon Transaction Builder is a powerful and user-friendly tool that empowers developers to streamline smart contract interaction in their Eidolon projects. By simplifying the code generation process and providing an intuitive interface, developers can efficiently harness the power of blockchain technology while focusing on building engaging gameplay experiences.