-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove client options, update tests and readme
- Loading branch information
1 parent
f3075dc
commit 9c29e82
Showing
6 changed files
with
90 additions
and
55 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,76 @@ dotnet add package Thirdweb | |
using Thirdweb; | ||
|
||
// Create a client | ||
var clientOptions = new ThirdwebClientOptions(secretKey: secretKey); | ||
var client = new ThirdwebClient(clientOptions); | ||
var client = new ThirdwebClient(secretKey: secretKey); | ||
|
||
// Interact with a contract | ||
var contractOptions = new ThirdwebContractOptions(client: client, address: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", chain: 1, abi: "function name() view returns (string)"); | ||
var contract = new ThirdwebContract(contractOptions); | ||
var readResult = await ThirdwebContract.ReadContract<string>(contract, "name"); | ||
var readResult = await ThirdwebContract.ReadContract<string>(client: client, address: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", chain: 1, abi: "function name() view returns (string)"); | ||
Console.WriteLine($"Contract read result: {readResult}"); | ||
|
||
// Or directly interact with the RPC | ||
var rpc = ThirdwebRPC.GetRpcInstance(client, 1); | ||
var blockNumber = await rpc.SendRequestAsync<string>("eth_blockNumber"); | ||
Console.WriteLine($"Block number: {blockNumber}"); | ||
|
||
// Create accounts | ||
var privateKeyAccount = new PrivateKeyAccount(client, privateKey); | ||
var embeddedAccount = new EmbeddedAccount(client, "[email protected]"); | ||
var smartAccount = new SmartAccount(client, embeddedAccount, "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", true, 421614); | ||
|
||
// Attempt to connect pk accounts | ||
await privateKeyAccount.Connect(); | ||
await embeddedAccount.Connect(); | ||
|
||
// Relog if embedded account not logged in | ||
if (!await embeddedAccount.IsConnected()) | ||
{ | ||
await embeddedAccount.SendOTP(); | ||
Console.WriteLine("Please submit the OTP."); | ||
var otp = Console.ReadLine(); | ||
(var embeddedAccountAddress, var canRetry) = await embeddedAccount.SubmitOTP(otp); | ||
if (embeddedAccountAddress == null && canRetry) | ||
{ | ||
Console.WriteLine("Please submit the OTP again."); | ||
otp = Console.ReadLine(); | ||
(embeddedAccountAddress, _) = await embeddedAccount.SubmitOTP(otp); | ||
} | ||
if (embeddedAccountAddress == null) | ||
{ | ||
Console.WriteLine("OTP login failed. Please try again."); | ||
return; | ||
} | ||
} | ||
|
||
// Connect the smart account with embedded signer and grant a session key to pk account | ||
await smartAccount.Connect(); | ||
_ = await smartAccount.CreateSessionKey( | ||
signerAddress: await privateKeyAccount.GetAddress(), | ||
approvedTargets: new List<string>() { Constants.ADDRESS_ZERO }, | ||
nativeTokenLimitPerTransactionInWei: "0", | ||
permissionStartTimestamp: "0", | ||
permissionEndTimestamp: (Utils.GetUnixTimeStampNow() + 86400).ToString(), | ||
reqValidityStartTimestamp: "0", | ||
reqValidityEndTimestamp: Utils.GetUnixTimeStampIn10Years().ToString() | ||
); | ||
|
||
// Reconnect to same smart account with pk account as signer | ||
smartAccount = new SmartAccount(client, privateKeyAccount, "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", true, 421614, await smartAccount.GetAddress()); | ||
await smartAccount.Connect(); | ||
|
||
// Log addresses | ||
Console.WriteLine($"PrivateKey Account: {await privateKeyAccount.GetAddress()}"); | ||
Console.WriteLine($"Embedded Account: {await embeddedAccount.GetAddress()}"); | ||
Console.WriteLine($"Smart Account: {await smartAccount.GetAddress()}"); | ||
|
||
// Initialize wallet | ||
var thirdwebWallet = new ThirdwebWallet(); | ||
await thirdwebWallet.Initialize(new List<IThirdwebAccount> { privateKeyAccount, embeddedAccount, smartAccount }); | ||
thirdwebWallet.SetActive(await smartAccount.GetAddress()); | ||
Console.WriteLine($"Active account: {await thirdwebWallet.GetAddress()}"); | ||
|
||
// Sign, triggering deploy as needed and 1271 verification | ||
var message = "Hello, Thirdweb!"; | ||
var signature = await thirdwebWallet.PersonalSign(message); | ||
Console.WriteLine($"Signed message: {signature}"); | ||
``` |
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
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
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
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
This file was deleted.
Oops, something went wrong.