OMG this works perfectly !!!
Can’t wait for the nft snippets
you should be able to use the snippets i sent to transfer nft, you can use an nft abi, then call the transfer function on the abi (it might have a different name) and then pass in the parameters and it will work as planned.
Note that the sending of custom erc is not unique , you can change the contract address and amount, to send any amount of any token on that chain by calling a a general erc20 contract function in the abi (the abi is in the code, i commented it out).
i have given a layout to be ablle to call smart contract functions, you can try it out and test if for your different functions.
Hi,
Not sure what I might be doing wrong, but I’m trying to implement a LiveQuery on a custom object. I have a custom PlayerData object / database table that I want to monitor. I’m calling the below code in a function but I am not receiving any event callbacks.
I’m currently use this PlayerData object to successfully store / retrieve values from the Moralis DB & have had no issues there, just can’t seem to get any output from the callbacks when there is a modification to the table and / or the data in it.
Thanks!
var query = await MoralisInterface.GetClient().Query<PlayerData>();
MoralisLiveQueryCallbacks<PlayerData> callbacks = new MoralisLiveQueryCallbacks<PlayerData>();
callbacks.OnConnectedEvent += (() => { Console.WriteLine("Connection Established."); });
callbacks.OnSubscribedEvent += ((requestId) => { Console.WriteLine($"Subscription {requestId} created."); });
callbacks.OnUnsubscribedEvent += ((requestId) => { Console.WriteLine($"Unsubscribed from {requestId}."); });
callbacks.OnErrorEvent += ((ErrorMessage em) =>
{
Console.WriteLine($"***** ERROR: code: {em.code}, msg: {em.error}, requestId: {em.requestId}");
});
callbacks.OnCreateEvent += ((item, requestId) =>
{
Console.WriteLine($"***** Created");
});
callbacks.OnUpdateEvent += ((item, requestId) =>
{
Console.WriteLine($"***** Updated");
});
callbacks.OnDeleteEvent += ((item, requestId) =>
{
Console.WriteLine($"***** Deleted");
});
callbacks.OnGeneralMessageEvent += ((text) =>
{
Console.WriteLine($"***** Websocket message: {text}");
});
MoralisLiveQueryController.AddSubscription<PlayerData>("PlayerData", query, callbacks);
Using Unity remote how can I use Deep linking ?
yes it should support deep linking
are you sure Console.WriteLine
displays on the unity console, you can try testing it ?
if it doesn’t , you can try print()
or Debug.log()
@jcm, @0xprof is correct. Instead of Console.log use Debug.Log.
I just updated the README.md for this. Sorry about the confusion. I copied that block of code straight from my integrated test case.
David
Hello, the Wallet Connect code does use deep linking for mobile wallet connections. You do not need to setup this up yourself.
Yes this was working as of a week ago on Android. I will double check to make sure it is still fine.
David
NftOwnerCollection balance = await MoralisInterface.GetClient().Web3Api.Account.GetNFTsForContract(address.ToLower(), tokenAddress, ChainList.eth);
I am getting this error “ApiException: Error calling GetNFTsForContract: Object reference not set to an instance of an object” only on android, it’s working fine on editor.
Details :
E Unity : ApiException: Error calling GetNFTsForContract: Object reference not set to an instance of an object
E Unity : at Moralis.Web3Api.CloudApi.AccountApi.GetNFTsForContract (System.String address, System.String tokenAddress, Moralis.Web3Api.Models.ChainList chain, System.String format, System.Nullable1[T] offset, System.Nullable
1[T] limit) [0x00321] in F:\NewGame\Assets\MoralisWeb3ApiSdk\Moralis\Moralis.Web3Api\CloudApi\AccountApi.cs:446
Unity : at SwordNFT.MoralisTest () [0x00179] in F:\NewGame\Assets\Scripts\SwordNFT.cs:262
E Unity : at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in <57faacfd2e7144baaa50d26ab4b3b712>:0
E Unity : at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153
E Unity : at UnityEngine.UnitySynchronizationContext.Exec () [0x00056] in /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchroniz
Arf the struggle is real with ERC1155 haha sorry.
this is my code, trying to use the standard SafeTransferFrom function from the ERC1155 standard:
public string ABINft;
public async void SendErc1155()
{
MoralisInterface.InsertContractInstance("1155NFT", ABINft, "mumbai", erc1155Address);
// Set gas estimate
HexBigInteger gas = new HexBigInteger(80000);
object[] pars = { senderAccount, receiverAccount, 2, 1, 0 };
// Call the contract to claim the NFT reward.
string resp = await MoralisInterface.SendEvmTransactionAsync("1155NFT", "mumbai", "safeTransferFrom", senderAccount, gas, new HexBigInteger("0x0"), pars);
print(resp);
}
where 2 is the ID of the NFT, 1 the amount and 0 the data like such in Remix:
my error : “Evm Transaction failed: byte[] value expected for type ‘bytes’”
same error when I try to declare a variable of type:
byte b = 0;
I feel I’m on the verge of making it work…
Hi fam,
Thanks for your amazing work !
creating a marketplace where people could buy displayed ERC1155 NFTs with specific ERC20 tokens.
I couldn’t find a working solution for that.
Do you have any direction for that ?
For now, I managed to:
- authentificate
- show custom token balance
- send custom token to specific address
- show owned nfts
Thanks in advance.
Trying it myself …
It worked for me. From Android Studio log:
2022-03-03 07:48:17.540 13840-13871/com.DefaultCompany.v108 I/Unity: Already Owns Mug.
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
AwardableController/<Update>d__6:MoveNext () (at F:/projects/unity/v108/Assets/MoralisWeb3ApiSdk/Example/Scripts/AwardableController.cs:101)
This debug statement only happens if the Web3Api call returns and the result contains the target TokenId
Since you are using custom code in the sample you sent:
- is address non-null?
- Is tokenAddress non-null?
- Has MoralisInterface been initialized prior to calling your test method?
Are you creating this using Unity for game?
ok, there should be two safeTransferFrom function ?
i saw two on erc 721, i took the parameter byte with the other normal parameters, the other one did not take it but took the other normal parameters
There is only one …
There is one called safeBatchTransferFrom, but takes in the same inputs…
I made this test method and it worked for me:
public async static Task TransferNft()
{
// Need the user for the wallet address
MoralisUser user = await MoralisInterface.GetUserAsync();
string addr = user.authData["moralisEth"]["id"].ToString();
BigInteger bi = 0;
if (BigInteger.TryParse(Constants.MUG_TOKEN_ID, out bi))
{
// Convert token id to hex as this is what the contract call expects
object[] pars = new object[] {
// from
addr,
// to
"0xc539a39719Ad4D2DE7bf6f1e16F86383B6FF59C6",
// Token Id
bi.ToString(),
// Amount (count)
(new HexBigInteger(1)).ToString(),
// data
new byte[] {0}
};
// Set gas estimate
HexBigInteger gas = new HexBigInteger(30000);
try
{
// Call the contract to transfer the NFT.
string resp = await MoralisInterface.SendEvmTransactionAsync("Rewards", "mumbai", "safeTransferFrom", addr, gas, new HexBigInteger("0x0"), pars);
Debug.Log($"$Send Transaction respo: {resp}");
}
catch (Exception exp)
{
Debug.Log($"Send transaction failed: {exp.Message}");
}
}
}
This is non-WebGL
Yes I am
Yeayyy this worksss !! Thanks x1000 @dgoodrich and @0xprof.
Made my day.
Just a note:
Why does the nft still appears on my metamask app like I still own it ?
Is this coming from them ?
Thanks again for your amazing support guys.
Double check using the etherscan associated with the chain you are targeting and look at the transactions for you wallet.
Did the transaction actually succeed? If so I do not know why metamask still shows that address still owns the NFT.
also try logging out and into the wallet to see if that clears it up .