Created
June 27, 2018 16:38
-
-
Save tmyngu11/71d1151a99ee86edb6ad7315760f7862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Nethereum.JsonRpc.UnityClient; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using UnityEngine; | |
public class MyNinjasScript : MonoBehaviour | |
{ | |
// This is the testnet we are going to use for our contract | |
private string _url = "https://mainnet.infura.io/V2KrUKkJJuHOEkqHzotR"; | |
private NinjaCoreContractService ninjaCoreContractService = new NinjaCoreContractService(); | |
// Use this for initialization | |
void Start() | |
{ | |
StartCoroutine(getPlayerNinjas("0x72e2e5f980404c4e7e9d4d48b7eb6f4939dea95a")); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
public IEnumerator getPlayerNinjas(string owner) | |
{ | |
var tokensRequest = new EthCallUnityRequest(_url); | |
var tokensInput = ninjaCoreContractService.CreatetokensOfOwnerInput(owner); | |
yield return tokensRequest.SendRequest(tokensInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()); | |
TokensOfOwnerOutputDTO n = ninjaCoreContractService.DecodetokensOfOwnerFunction(tokensRequest.Result); | |
Debug.Log(n); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Nethereum.ABI.FunctionEncoding; | |
using Nethereum.ABI.FunctionEncoding.Attributes; | |
using Nethereum.Contracts; | |
using Nethereum.RPC.Eth.DTOs; | |
using System; | |
using System.Threading.Tasks; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Numerics; | |
using UnityEngine; | |
public class NinjaCoreContractService : MonoBehaviour | |
{ | |
// We define the ABI of the contract we are going to use. | |
public static string ABI = @"[{'constant':true,'inputs':[{'name':'_id','type':'uint256'}],'name':'getNinja','outputs':[{'name':'isGestating','type':'bool'},{'name':'isReady','type':'bool'},{'name':'cooldownIndex','type':'uint256'},{'name':'nextActionAt','type':'uint256'},{'name':'siringWithId','type':'uint256'},{'name':'birthTime','type':'uint256'},{'name':'matronId','type':'uint256'},{'name':'sireId','type':'uint256'},{'name':'generation','type':'uint256'},{'name':'genes','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'cfoAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'promoCreatedCount','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'name','outputs':[{'name':'','type':'string'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_to','type':'address'},{'name':'_tokenId','type':'uint256'}],'name':'approve','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'ceoAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'GEN0_STARTING_PRICE','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'pregnantNinjas','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_address','type':'address'}],'name':'setSiringAuctionAddress','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_contract','type':'address'}],'name':'addExtension','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'totalSupply','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'_ninjaId','type':'uint256'}],'name':'isPregnant','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'GEN0_AUCTION_DURATION','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'siringAuction','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_contract','type':'address'}],'name':'removeExtension','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_from','type':'address'},{'name':'_to','type':'address'},{'name':'_tokenId','type':'uint256'}],'name':'transferFrom','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_address','type':'address'}],'name':'setGeneScienceAddress','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_newCEO','type':'address'}],'name':'setCEO','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_newCOO','type':'address'}],'name':'setCOO','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'},{'name':'_startingPrice','type':'uint256'},{'name':'_endingPrice','type':'uint256'},{'name':'_duration','type':'uint256'}],'name':'createSaleAuction','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[],'name':'unpause','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_genes','type':'uint256'},{'name':'_owner','type':'address'}],'name':'createPromoNinja','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'sireAllowedToAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'_matronId','type':'uint256'},{'name':'_sireId','type':'uint256'}],'name':'canBreedWith','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'},{'name':'_startingPrice','type':'uint256'},{'name':'_endingPrice','type':'uint256'},{'name':'_duration','type':'uint256'}],'name':'createSiringAuction','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'val','type':'uint256'}],'name':'setAutoBirthFee','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_addr','type':'address'},{'name':'_sireId','type':'uint256'}],'name':'approveSiring','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_newCFO','type':'address'}],'name':'setCFO','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'secs','type':'uint256'}],'name':'setSecondsPerBlock','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'paused','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[],'name':'withdrawBalance','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_tokenId','type':'uint256'}],'name':'ownerOf','outputs':[{'name':'owner','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'GEN0_CREATION_LIMIT','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'newContractAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_address','type':'address'}],'name':'setSaleAuctionAddress','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_owner','type':'address'}],'name':'balanceOf','outputs':[{'name':'count','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_v2Address','type':'address'}],'name':'setNewAddress','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'ninjaIndexToApproved','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'secondsPerBlock','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[],'name':'pause','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_owner','type':'address'}],'name':'tokensOfOwner','outputs':[{'name':'ownerTokens','type':'uint256[]'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_matronId','type':'uint256'}],'name':'giveBirth','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_ninjaId','type':'uint256'}],'name':'extGetLock','outputs':[{'name':'','type':'uint16'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[],'name':'withdrawAuctionBalances','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_matronId','type':'uint256'},{'name':'_sireId','type':'uint256'},{'name':'_generation','type':'uint256'},{'name':'_genes','type':'uint256'},{'name':'_owner','type':'address'}],'name':'extCreateNinja','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'symbol','outputs':[{'name':'','type':'string'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'destroyedNinjas','outputs':[{'name':'','type':'uint32'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'cooldowns','outputs':[{'name':'','type':'uint32'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_to','type':'address'},{'name':'_tokenId','type':'uint256'}],'name':'transfer','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'cooAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'autoBirthFee','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'}],'name':'extDestroyNinja','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_genes','type':'uint256'}],'name':'createGen0Auction','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'}],'name':'destroyNinja','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_ninjaId','type':'uint256'}],'name':'isReadyToBreed','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'PROMO_CREATION_LIMIT','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'saleAuction','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'},{'name':'_mask','type':'uint16'}],'name':'extLockNinja','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_sireId','type':'uint256'},{'name':'_matronId','type':'uint256'}],'name':'bidOnSiringAuction','outputs':[],'payable':true,'stateMutability':'payable','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'ninjaIndexToOwner','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'gen0CreatedCount','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'geneScience','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_matronId','type':'uint256'},{'name':'_sireId','type':'uint256'}],'name':'breedWithAuto','outputs':[],'payable':true,'stateMutability':'payable','type':'function'},{'constant':false,'inputs':[{'name':'_ninjaId','type':'uint256'},{'name':'_mask','type':'uint16'}],'name':'extUnlockNinja','outputs':[{'name':'','type':'uint16'}],'payable':false,'stateMutability':'nonpayable','type':'function'},{'inputs':[],'payable':false,'stateMutability':'nonpayable','type':'constructor'},{'payable':true,'stateMutability':'payable','type':'fallback'},{'anonymous':false,'inputs':[{'indexed':false,'name':'owner','type':'address'},{'indexed':false,'name':'matronId','type':'uint256'},{'indexed':false,'name':'sireId','type':'uint256'},{'indexed':false,'name':'cooldownEndBlock','type':'uint256'}],'name':'Pregnant','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'from','type':'address'},{'indexed':false,'name':'to','type':'address'},{'indexed':false,'name':'tokenId','type':'uint256'}],'name':'Transfer','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'owner','type':'address'},{'indexed':false,'name':'approved','type':'address'},{'indexed':false,'name':'tokenId','type':'uint256'}],'name':'Approval','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'ninjaId','type':'uint256'},{'indexed':false,'name':'mask','type':'uint16'}],'name':'Lock','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'owner','type':'address'},{'indexed':false,'name':'ninjaId','type':'uint256'},{'indexed':false,'name':'matronId','type':'uint256'},{'indexed':false,'name':'sireId','type':'uint256'},{'indexed':false,'name':'genes','type':'uint256'},{'indexed':false,'name':'birthTime','type':'uint256'}],'name':'Birth','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'newContract','type':'address'}],'name':'ContractUpgrade','type':'event'}]"; | |
// And we define the contract address here, in this case is a simple ping contract | |
private static string contractAddress = "0xfc1435d094bfbd07d0a2521e072dcdb8affbec41"; | |
// We define a new contract (Netherum.Contracts) | |
private Contract contract; | |
public NinjaCoreContractService() | |
{ | |
// Here we assign the contract as a new contract and we send it the ABI and contact address | |
this.contract = new Contract(null, ABI, contractAddress); | |
} | |
/////////////////////// GET NINJA //////////////////////////// | |
public Function tokensOfOwner() | |
{ | |
return contract.GetFunction("tokensOfOwner"); | |
} | |
public CallInput CreatetokensOfOwnerInput(string owner) | |
{ | |
var function = tokensOfOwner(); | |
return function.CreateCallInput(owner); | |
} | |
public TokensOfOwnerOutputDTO DecodetokensOfOwnerFunction(string result) | |
{ | |
var function = tokensOfOwner(); | |
return function.DecodeDTOTypeOutput<TokensOfOwnerOutputDTO>(result); | |
} | |
} | |
[FunctionOutput] | |
public class TokensOfOwnerOutputDTO | |
{ | |
[Parameter("uint256[]", "ownerTokens", 1)] | |
public List<BigInteger> OwnerTokens { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment