Welcome to the Beamable Theta Sample project! This is a Unity project that demonstrates how to integrate the Theta blockchain into a Beamable powered game.
Before getting started, please head to Beamable and sign up. You should have the following tools installed on your development machine.
ERC1155 is a hybrid token standard supporting both fungible and non-fungible tokens. It allows for the creation
of a single smart contract that can support multiple tokens, making it more cost-efficient than creating separate
contracts for each token. This is particularly useful in gaming, where a game may have a large number of
unique items or characters that need to be represented as tokens. Additionally, ERC1155 supports batch
transactions, which means that multiple tokens can be transferred in a single transaction, reducing gas costs
and improving the overall user experience. Our integration uses a single ERC1155 smart contract to represent
all game tokens, making it more efficient and cost-effective for both developers and users.
Source: Default Smart Contract
We are using the solc Solidity compiler wrapped inside of the integration microservice to compile the smart contract at runtime. You can clone this repository and modify the smart contract per your requirements. We tried to create a contract that is generic as possible for most use-cases.
To get started with this sample project, use git
to clone this project, and open it
with Unity 2022.
The Theta integration is portable to other Beamable Unity projects. The Microservice and Microstorage code can be imported into a target project. The best way is to use Unity Package Manager and add a part of this repository as an external package.
Before doing this, please ensure that the target project already has Beamable installed
In the Unity Package Manager, add a package via git-link.
for com.beamable.theta
and use the following git-link.
https://github.com/beamable/theta-example-unity.git?path=/Packages/com.beamable.theta#0.0.6
Note: the end of the link includes the version number. You view the available versions by looking at this repositories git tags.
This sample project includes one Theta federated item - BeamSword, and one Theta federated currency - BeamCoin. You can enable federation on any item or currency.
- Set your RPC URI as a realm config value "RPCEndpoint" (see Configuration)
- Theta Testnet RPC: https://eth-rpc-api-testnet.thetatoken.org/rpc
- Theta Mainnet RPC: https://eth-rpc-api.thetatoken.org/rpc
- Publish the ThetaFederation microservice along with the ThetaStorage microstorage.
- Open the Portal an wait for the microservice to get into the running state.
- Explore the microservice logs and microstorage data. Microservice should create and store your developer wallet on first run.
- Use a Theta Web Wallet to request some test TFUEL tokens for your developer wallet.
- To find your Developer wallet address visit the Beamable Portal under Operate > Microservices
- Under Microservice Actions click Docs
- This will open Microservice Swagger documentation
- Call GetRealmAccount endpoint
- This output your developer wallet address
- Initialize Default Contract
- Call InitializeContract endpoint
- This compile and publish the smart contract and output its address
- Import the Sample scene to initialize your wallet
- Open the Unity Package Manager
- Select the Theta Package and navigate to the "Samples" tab
- Import the Demo sample project
- Open the Main scene and run it
- Click the Initialize wallet button
- Confirm in the portal that your player has the wallet
NOTE: First request to the microservice will initiate the compile and deploy procedure for the smart contract. Depending on your RPC endpoint, it may result in a timeout. Be sure to check the microservice logs.
We're using our existing Content System backed by AWS S3 and AWS CloudFront CDN for storing NFT metadata. Every property you specify in the Inventory CreateItemRequest
will become a NFT metadata property.
To specify a root level metadata property, like "image" or "description", you just prefix the property name with a '$' character.
Example CreateItemRequest
:
{
"contentId": "items.sword",
"properties": [
{
"name": "$image",
"value": "someimage"
},
{
"name": "$description",
"value": "strong sword"
},
{
"name": "damage",
"value": "500"
},
{
"name": "price",
"value": "350"
}
]
}
Resulting metadata file:
{
"image": "someimage",
"description": "strong sword",
"properties": [
{
"name": "damage",
"value": "500"
},
{
"name": "price",
"value": "350"
}
]
}
Configuration defaults are hard-coded inside Runtime/ThetaFederation/Configuration.cs
You can override the values using the realm configuration.
Default values:
Namespace | Key | Default value | Description |
---|---|---|---|
theta_federation | RPCEndpoint | Cluster RPC API URI | |
theta_federation | AllowManagedAccounts | true | Allow custodial wallets for players |
theta_federation | AuthenticationChallengeTtlSec | 600 | Authentication challenge TTL |
theta_federation | ReceiptPoolIntervalMs | 200 | Pooling interval when fetching a transaction receipt |
theta_federation | TransactionRetries | 10 | Failed transaction retry count |
theta_federation | MaximumGas | 2_000_000 | Max transaction gas amount |
theta_federation | GasPriceCacheTtlSec | 3 | Cache time for previous transaction gas amount |
theta_federation | GasExtraPercent | 0 | Increase transaction gas amount |
theta_federation | CollectionName | Collection name | |
theta_federation | CollectionDescription | Collection description | |
theta_federation | CollectionImage | Collection image URL | |
theta_federation | CollectionLink | Collection external link |
IMPORTANT: Configuration is loaded when the service starts. Any configuration change requires a service restart.