Skip to content

Commit 162f874

Browse files
committed
Cross platform BigInteger chain id support + add Xai L3
1 parent f77265c commit 162f874

File tree

6 files changed

+80550
-80272
lines changed

6 files changed

+80550
-80272
lines changed

Assets/Thirdweb/Core/Plugin/thirdweb.jslib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var plugin = {
6969
window.bridge
7070
.connect(
7171
UTF8ToString(wallet),
72-
chainId,
72+
UTF8ToString(chainId),
7373
UTF8ToString(password),
7474
UTF8ToString(email),
7575
UTF8ToString(personalWallet)
@@ -100,7 +100,7 @@ var plugin = {
100100
stringToUTF8(id, idPtr, idSize);
101101
// execute bridge call
102102
window.bridge
103-
.switchNetwork(chainId)
103+
.switchNetwork(UTF8ToString(chainId))
104104
.then(() => {
105105
dynCall_viii(cb, idPtr, null, null);
106106
})

Assets/Thirdweb/Core/Scripts/Bridge.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public static async Task<string> Connect(WalletConnection walletConnection)
9494
ThirdwebConnect(
9595
taskId,
9696
walletConnection.provider.ToString().Substring(0,1).ToLower() + walletConnection.provider.ToString().Substring(1),
97-
(int)walletConnection.chainId, string.IsNullOrEmpty(walletConnection.password) ? Utils.GetDeviceIdentifier() : walletConnection.password,
97+
walletConnection.chainId.ToString(),
98+
string.IsNullOrEmpty(walletConnection.password) ? Utils.GetDeviceIdentifier() : walletConnection.password,
9899
walletConnection.email,
99100
walletConnection.personalWallet.ToString().Substring(0,1).ToLower() + walletConnection.personalWallet.ToString().Substring(1),
100101
jsCallback
@@ -120,7 +121,7 @@ public static async Task Disconnect()
120121
await task.Task;
121122
}
122123

123-
public static async Task SwitchNetwork(int chainId)
124+
public static async Task SwitchNetwork(string chainId)
124125
{
125126
if (!Utils.IsWebGLBuild())
126127
{
@@ -214,11 +215,11 @@ public static async Task<string> ExportWallet(string password)
214215
[DllImport("__Internal")]
215216
private static extern string ThirdwebInitialize(string chainOrRPC, string options);
216217
[DllImport("__Internal")]
217-
private static extern string ThirdwebConnect(string taskId, string wallet, int chainId, string password, string email, string personalWallet, Action<string, string, string> cb);
218+
private static extern string ThirdwebConnect(string taskId, string wallet, string chainId, string password, string email, string personalWallet, Action<string, string, string> cb);
218219
[DllImport("__Internal")]
219220
private static extern string ThirdwebDisconnect(string taskId, Action<string, string, string> cb);
220221
[DllImport("__Internal")]
221-
private static extern string ThirdwebSwitchNetwork(string taskId, int chainId, Action<string, string, string> cb);
222+
private static extern string ThirdwebSwitchNetwork(string taskId, string chainId, Action<string, string, string> cb);
222223
[DllImport("__Internal")]
223224
private static extern string ThirdwebFundWallet(string taskId, string payload, Action<string, string, string> cb);
224225
[DllImport("__Internal")]

Assets/Thirdweb/Core/Scripts/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public static string EncryptAndGenerateKeyStore(EthECKey ecKey, string password)
343343
return keyStoreService.SerializeKeyStoreToJson(keyStore);
344344
}
345345

346-
public static Account GenerateRandomAccount(int chainId)
346+
public static Account GenerateRandomAccount(BigInteger chainId)
347347
{
348348
byte[] seed = new byte[32];
349349
using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())

Assets/Thirdweb/Core/Scripts/Wallet.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public async Task<BigInteger> GetChainId()
308308
{
309309
if (Utils.IsWebGLBuild())
310310
{
311-
return await Bridge.InvokeRoute<int>(getRoute("getChainId"), new string[] { });
311+
return await Bridge.InvokeRoute<BigInteger>(getRoute("getChainId"), new string[] { });
312312
}
313313
else
314314
{
@@ -329,13 +329,7 @@ public async Task SwitchNetwork(BigInteger chainId)
329329

330330
if (Utils.IsWebGLBuild())
331331
{
332-
int safeId;
333-
if (!int.TryParse(chainId.ToString(), out safeId))
334-
{
335-
throw new Exception("Chain ID too large for WebGL platforms");
336-
}
337-
338-
await Bridge.SwitchNetwork(safeId);
332+
await Bridge.SwitchNetwork(chainId.ToString());
339333
}
340334
else
341335
{

Assets/Thirdweb/Resources/all_chains.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19426,5 +19426,37 @@
1942619426
"standard": "none"
1942719427
}
1942819428
]
19429+
},
19430+
{
19431+
"name": "Xai Goerli Orbit",
19432+
"title": "Xai Goerli Orbit Testnet",
19433+
"chain": "ETH",
19434+
"rpc": ["https://testnet.xai-chain.net/rpc"],
19435+
"faucets": [],
19436+
"nativeCurrency": {
19437+
"name": "Xai Goerli Ether",
19438+
"symbol": "ETH",
19439+
"decimals": 18
19440+
},
19441+
"infoURL": "https://xai.games/",
19442+
"shortName": "xai-goerli",
19443+
"chainId": 47279324479,
19444+
"networkId": 47279324479,
19445+
"explorers": [
19446+
{
19447+
"name": "Xai Goerli Testnet Explorer",
19448+
"url": "https://testnet-explorer.xai-chain.net",
19449+
"standard": "EIP3091"
19450+
}
19451+
],
19452+
"parent": {
19453+
"type": "L2",
19454+
"chain": "eip155-421613",
19455+
"bridges": [
19456+
{
19457+
"url": "https://bridge.arbitrum.io"
19458+
}
19459+
]
19460+
}
1942919461
}
1943019462
]

0 commit comments

Comments
 (0)