Skip to content

Commit 61194f4

Browse files
committed
SwitchNetwork now part of IThirdwebWallet
`SmartWallet.SwitchNetwork` now also switches underlying wallet network. Also adds `SmartWallet.ActiveChain` property.
1 parent 3025488 commit 61194f4

File tree

5 files changed

+110
-68
lines changed

5 files changed

+110
-68
lines changed

Thirdweb.Tests/Thirdweb.Wallets/Thirdweb.Wallets.Tests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public WalletTests(ITestOutputHelper output)
1010
private async Task<SmartWallet> GetSmartAccount()
1111
{
1212
var privateKeyAccount = await PrivateKeyWallet.Generate(this.Client);
13-
var smartAccount = await SmartWallet.Create(personalWallet: privateKeyAccount, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
13+
var smartAccount = await SmartWallet.Create(personalWallet: privateKeyAccount, chainId: 421614);
1414
return smartAccount;
1515
}
1616

@@ -230,4 +230,21 @@ public async Task RecoverAddress_AllVariants_NullTests()
230230
);
231231
#nullable restore
232232
}
233+
234+
[Fact(Timeout = 120000)]
235+
public async Task SwitchNetwork_Success()
236+
{
237+
var smartWallet = await this.GetSmartAccount();
238+
var wrappedSmartWallet = await SmartWallet.Create(personalWallet: smartWallet, chainId: 421614);
239+
240+
Assert.Equal(421614, smartWallet.ActiveChainId);
241+
Assert.Equal(421614, wrappedSmartWallet.ActiveChainId);
242+
243+
await wrappedSmartWallet.SwitchNetwork(11155111);
244+
245+
Assert.Equal(11155111, wrappedSmartWallet.ActiveChainId);
246+
Assert.Equal(11155111, smartWallet.ActiveChainId);
247+
248+
await (await PrivateKeyWallet.Generate(this.Client)).SwitchNetwork(11155111);
249+
}
233250
}

Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ Task<List<LinkedAccount>> LinkAccount(
176176
/// <param name="willSelfExecute">Set to true if the wallet will also be the executor of the transaction, otherwise false.</param>
177177
/// <returns>The signed authorization as an <see cref="EIP7702Authorization"/> that can be used with <see cref="ThirdwebTransactionInput.AuthorizationList"/>.</returns>
178178
Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string contractAddress, bool willSelfExecute);
179+
180+
/// <summary>
181+
/// Attempts to set the active network to the specified chain ID.
182+
/// </summary>
183+
/// <param name="chainId">The chain ID to switch to.</param>
184+
Task SwitchNetwork(BigInteger chainId);
179185
}
180186

181187
/// <summary>

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,5 +986,10 @@ public Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string c
986986
throw new NotImplementedException();
987987
}
988988

989+
public Task SwitchNetwork(BigInteger chainId)
990+
{
991+
return Task.CompletedTask;
992+
}
993+
989994
#endregion
990995
}

Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,10 @@ public async Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, st
469469
return new EIP7702Authorization(chainId, contractAddress, nonce, authorizationSignature.V, authorizationSignature.R, authorizationSignature.S);
470470
}
471471

472+
public Task SwitchNetwork(BigInteger chainId)
473+
{
474+
return Task.CompletedTask;
475+
}
476+
472477
#endregion
473478
}

0 commit comments

Comments
 (0)