- Aptos is a Layer 1 blockchain built with a Rust-based programming language called Move
- Petra wallet is a crypto wallet on Aptos built by Aptos Labs
- Unity is a cross-platform game engine developed by Unity Technologies
You want to develop a game with pay-to-spawn functionality or NFT integration on the Aptos blockchain.
- How to connect/disconnect to Petra wallet?
- How to sign a message with Petra wallet?
- How to send a transaction with Petra wallet?
- How to communicate between the browser and the WebGL build?
The implementation consists of two core components
- Web3js.jslib
- Communication between JavaScript and browser
- Communication between JavaScript and C# (see
SendMessage
functions)
- MenuUI.cs
- Communication between C# and JavaScript (see functions with the attribute
[DllImport("__Internal")]
)
- Communication between C# and JavaScript (see functions with the attribute
Note
If you want to send transactions with your Petra wallet (or realize any other interaction with the blockchain), you need to add the Aptos SDK to your code.
In our case we added the line
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/index.global.js"></script>
to the index.html of the WebGL template.
https://aptos-petra-wallet-unity-integration-build.vercel.app