在游戏中集成区块链NFT支持已经成为2022年不可忽视的趋势。本文将介绍最新的4个 适合Unity游戏开发者的NFT SDK。
1、ChainSafe Gaming SDK
ChainSafe Gaming SDK的目的是帮助Unity开发者提供接入以太坊系列区块链并创建游戏NFT。
Chainsafe Gaming SDK内置ERC20、ERC721和ERC1155的访问能力,例如查看指定地址持有的 全部NFT:
1 2 3 4 5 6 |
string chain = "ethereum"; string network = "rinkeby"; // mainnet ropsten kovan rinkeby goerli string account = "0xebc0e6232fb9d494060acf580105108444f7c696"; string contract = ""; string response = await EVM.AllErc721(chain, network, account, contract); print(response); |
ChainSafe Gaming SDK目前支持的区块链包括:
| chain | network| |–|–| |ethereum | mainnet ropsten kovan rinkeby goerli | |avalanche| mainnet testnet | |binance | mainnet testnet | |moonbeam | mainnet testnet | |polygon | mainnet testnet | |xdai | mainnet testnet | |harmony | mainnet testnet |
- 下载地址:https://github.com/ChainSafe/web3.unity/releases
- SDK文档:https://chainsafe.github.io/game-docs/
2、Blockchain SDK by Enjin
Enjin提供的区块链SDK,可以帮助Unity开发者快速构造下一代区块链游戏,并且不需要写一行区块链代码。
Enjin SDK实际上是和Enjin的GraphQL后台API服务交互的,没有直接接入区块链。
- Unity商店下载:https://assetstore.unity.com/packages/tools/utilities/blockchain-sdk-by-enjin-124133
3、Moralis Metaverse SDK
Moralis元宇宙SDK声称可以轻松构建元宇宙应用和游戏,主要针对以太坊系列区块链。
Moralis将dAPP分成两个部分:
- 链上部分:包括智能合约、链上资产例如NFT通证、链上交易等
- 链下部分:用于从区块链采集数据的后台基础设施,为web app等提供api、建立区块链索引、提供实时告警等。
因此Moralis的SDK是和其后台服务(即链下部分)绑定的。
利用Moralis提供的JavaScript SDK可以轻松实现NFT通证的传递:
1 2 3 4 5 6 |
// sending a token with token id = 1 const options = {type: "erc721", receiver: "0x..", contractAddress: "0x..", tokenId: 1} let transaction = await Moralis.transfer(options) |
- SDK文档: https://docs.moralis.io/introduction/readme
- Moralis区块链项目模板:https://docs.moralis.io/moralis-server/getting-started/boilerplate-projects
- Moralis SDK:https://github.com/MoralisWeb3/Moralis-JS-SDK
4、Stratis Unity SDK
Stratis是一个高度去中心化的区块链开发平台,致力于为微软平台开发者提供区块链开发解决方案。 Stratis可以让任何人在几分钟内创建并管理区块链,同时可以定制用户自己的侧链,极大扩展了目标用户 群体的范围。
Stratis使用的是自己的区块链实现,因此连智能合约都是C#开发,例如下面这个Strais版本的Hello World合约 的完整实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using Stratis.SmartContracts; /// <summary> /// A basic "Hello World" smart contract /// </summary> [Deploy] public class HelloWorld : SmartContract { private string Greeting { get { return this.PersistentState.GetString("Greeting"); } set { this.PersistentState.SetString("Greeting", value); } } public HelloWorld(ISmartContractState smartContractState) : base(smartContractState) { this.Greeting = "Hello World!"; } public string SayHello() { return this.Greeting; } } |
- SDK下载:https://github.com/stratisproject/StratisUnitySDK
- 开发者文档:https://academy.stratisplatform.com/Developer%20Resources/developers-introduction.html