Releases: thirdweb-dev/dotnet
v2.18.0
What's Changed
Insight Indexer .NET Integration
Insight is an extremely useful and performant tool to query blockchain data and can decorate it quite nicely too.
Did you know that vitalik, on Ethereum, Polygon and Arbitrum alone owns 7811 ERC20s, 34,362 ERC721s and 2,818 ERC1155s?
Let's go through some examples!
Instantiation
using Thirdweb.Indexer;
// Create a ThirdwebInsight instance
var insight = await ThirdwebInsight.Create(client);Simple Args
// Setup some filters
var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
var chains = new BigInteger[] { 1, 137, 42161 };Fetching all tokens owned by a given address
// Fetch all token types
var tokens = await insight.GetTokens(address, chains);
Console.WriteLine($"ERC20 Count: {tokens.erc20Tokens.Length} | ERC721 Count: {tokens.erc721Tokens.Length} | ERC1155 Count: {tokens.erc1155Tokens.Length}");Fetching a specific type of token owned by a given address
// Fetch ERC20s only
var erc20Tokens = await insight.GetTokens_ERC20(address, chains);
Console.WriteLine($"ERC20 Tokens: {JsonConvert.SerializeObject(erc20Tokens, Formatting.Indented)}");
// Fetch ERC721s only
var erc721Tokens = await insight.GetTokens_ERC721(address, chains);
Console.WriteLine($"ERC721 Tokens: {JsonConvert.SerializeObject(erc721Tokens, Formatting.Indented)}");
// Fetch ERC1155s only
var erc1155Tokens = await insight.GetTokens_ERC1155(address, chains);
Console.WriteLine($"ERC1155 Tokens: {JsonConvert.SerializeObject(erc1155Tokens, Formatting.Indented)}");Fetching Events
Note: most of these parameters are optional (and some are not showcased here)
// Fetch events (great amount of optional filters available)
var events = await insight.GetEvents(
chainIds: new BigInteger[] { 1 }, // ethereum
contractAddress: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", // bored apes
eventSignature: "Transfer(address,address,uint256)", // transfer event
fromTimestamp: Utils.GetUnixTimeStampNow() - 3600, // last hour
sortBy: SortBy.TransactionIndex, // block number, block timestamp or transaction index
sortOrder: SortOrder.Desc, // latest first
limit: 5 // last 5 transfers
);
Console.WriteLine($"Events: {JsonConvert.SerializeObject(events, Formatting.Indented)}");Engine Blockchain API .NET Integration
Engine is one of thirdweb's most important products. We've created an EngineWallet class that can be used as an IThirdwebWallet and as such benefits from being compatible with the entire SDK!
Usage:
// EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
var engineWallet = await EngineWallet.Create(
client: client,
engineUrl: Environment.GetEnvironmentVariable("ENGINE_URL"),
authToken: Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN"),
walletAddress: Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS"),
timeoutSeconds: null, // no timeout
additionalHeaders: null // can set things like x-account-address if using basic session keys
);
// Simple self transfer
var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0);
Console.WriteLine($"Receipt: {receipt}");Integrated with last December's EIP-7702 release!
Additional Changes
- Arbitrum, Arbitrum Nova and Arbitrum Sepolia gas price related methods now get shortcut early and return maxFeePerGas = maxPriorityFeePerGas = current gas price.
Utils.GetChainMetadatachain id related variables updated frominttoBigInteger.
v2.17.2
What's Changed
- Smart Wallet transaction receipt polling can now time out based on your client "Other" timeout options, similar to normal transactions.
- Our dashboard now supports rotating your secret keys. Rotated secret keys are now supported in this version.
- You can now call
InAppWalletorEcosystemWallet'sCreatefunction and instantly login with atwAuthTokenOverridewhich would be an auth token/cookie that you would have retrieved from any other thirdweb app, such as a web app, electron launcher, or any app built using our various SDKs.
var forwardedWallet = await InAppWallet.Create(
client: myClient,
authProvider: AuthProvider.Github,
twAuthTokenOverride: "my.auth.token"
);Previously, it was only possible to go from .NET to other React apps using GenerateExternalLoginLink, this unlocks the other way.
v2.17.1
What's Changed
- Fixed
NFT.QuantityOwnedfor ERC1155 returning incorrect data in some cases when used throughERC1155_GetOwnedNFTs.
v2.17.0
What's Changed
Nebula AI .NET Integration (Beta) in #122
The last piece of the puzzle required to create .NET apps and games leveraging a blockchain-powered AI assistant or NPC that also has the power to fully execute transactions. Further enhanced when combined with Server Wallets and Account Abstraction.
Read, Write, Reason.
The best way to understand is to look at examples.
We'll prepare some context for the AI - here, we'll generate a basic PrivateKeyWallet and upgrade it to a SmartWallet on Sepolia.
// Prepare some context
var myChain = 11155111; // Sepolia
var mySigner = await PrivateKeyWallet.Generate(client);
var myWallet = await SmartWallet.Create(mySigner, myChain);
var myContractAddress = "0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8"; // DropERC1155
var usdcAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"; // Sepolia USDCA one liner creates a Nebula session.
// Create a Nebula session
var nebula = await ThirdwebNebula.Create(client);You can Chat with Nebula. The Chat method accepts any IThirdwebWallet as an optional parameter, context will automatically be updated.
// Chat, passing wallet context
var response1 = await nebula.Chat(message: "What is my wallet address?", wallet: myWallet);
Console.WriteLine($"Response 1: {response1.Message}");You may also pass it smart contract context.
// Chat, passing contract context
var response2 = await nebula.Chat(
message: "What's the total supply of token id 0 for this contract?",
context: new NebulaContext(contractAddresses: new List<string> { myContractAddress }, chainIds: new List<BigInteger> { myChain })
);
Console.WriteLine($"Response 2: {response2.Message}");You can have a full on conversation with it with our Chat override accepting multiple messages.
// Chat, passing multiple messages and context
var response3 = await nebula.Chat(
messages: new List<NebulaChatMessage>
{
new($"Tell me the name of this contract: {myContractAddress}", NebulaChatRole.User),
new("The name of the contract is CatDrop", NebulaChatRole.Assistant),
new("What's the symbol of this contract?", NebulaChatRole.User),
},
context: new NebulaContext(contractAddresses: new List<string> { myContractAddress }, chainIds: new List<BigInteger> { myChain })
);
Console.WriteLine($"Response 3: {response3.Message}");Chatting is cool, but what if I just want it to do things and stop talking so much?
You can Execute transactions directly with a simple prompt.
// Execute, this directly sends transactions
var executionResult = await nebula.Execute("Approve 1 USDC to vitalik.eth", wallet: myWallet, context: new NebulaContext(contractAddresses: new List<string>() { usdcAddress }));
if (executionResult.TransactionReceipts != null && executionResult.TransactionReceipts.Count > 0)
{
Console.WriteLine($"Receipt: {executionResult.TransactionReceipts[0]}");
}
else
{
Console.WriteLine($"Message: {executionResult.Message}");
}Similarly, Execute can take in multiple messages.
// Batch execute
var batchExecutionResult = await nebula.Execute(
new List<NebulaChatMessage>
{
new("What's the address of vitalik.eth", NebulaChatRole.User),
new("The address of vitalik.eth is 0xd8dA6BF26964aF8E437eEa5e3616511D7G3a3298", NebulaChatRole.Assistant),
new("Approve 1 USDC to them", NebulaChatRole.User),
},
wallet: myWallet,
context: new NebulaContext(contractAddresses: new List<string>() { usdcAddress })
);
if (batchExecutionResult.TransactionReceipts != null && batchExecutionResult.TransactionReceipts.Count > 0)
{
Console.WriteLine($"Receipts: {JsonConvert.SerializeObject(batchExecutionResult.TransactionReceipts, Formatting.Indented)}");
}
else
{
Console.WriteLine($"Message: {batchExecutionResult.Message}");
}Enhanced Analytics in #125
We've added transaction and connection analytics that will show up on your thirdweb dashboard and give you a better sense of your users' activities - make sure you grab this version to get the benefits!
If you've read this far, access Nebula and start building cool things. You're early - a full stack blockchain integration powered by AI is not something you see in .NET land too often, make use of thirdweb to build next-gen applications, and reach out to us!
v2.16.0
What's Changed
AuthProvider.SiweExternal - SIWE, OAuth style
Depending on the framework, or on the external wallet platform support, you may not have direct access to every single wallet out there.
This new AuthProvider allows you to login to otherwise native-unavailable wallets such as Abstract Wallet & Coinbase Smart Wallet through a flow similar to OAuth, using SIWE.
It'll redirect you to static.thirdweb.com and use our React SDK and other wallet SDKs as needed, unlocking the ability to login (or link) with any wallet thirdweb supports on web, from runtime platforms that would otherwise be unsupported by said wallet, and create an In-App or Ecosystem Wallet out of it.
Windows Console Example:
var inAppWalletSiweExternal = await InAppWallet.Create(client: client, authProvider: AuthProvider.SiweExternal);
var address = await inAppWalletSiweExternal.LoginWithSiweExternal(
isMobile: false,
browserOpenAction: (url) =>
{
var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
_ = Process.Start(psi);
},
forceWalletIds: new List<string> { "io.metamask", "com.coinbase.wallet", "xyz.abs" }
);You can now override the default session id used with Guest authentication
This is useful when you want your guest mode to be tied to a unique device identifier, and depending on your framework there may be various APIs to fetch such identifiers that you may want to use.
Example:
var guestWallet = await EcosystemWallet.Create(
ecosystemId: "ecosystem.the-bonfire",
client: client,
authProvider: AuthProvider.Guest
);
var address = await guestWallet.LoginWithGuest(SomeSystemInfoAPI.deviceUniqueIdentifier);v2.15.0
v2.14.0
What's Changed
- Added
AuthProvider.Backendas a server-side way to create In-App or Ecosystem Wallets. Simply pass awalletSecretidentifier.
var inAppWalletBackend = await InAppWallet.Create(
client: client,
authProvider: AuthProvider.Backend,
walletSecret: "very-secret"
);
var address = await inAppWalletBackend.LoginWithBackend();v2.13.0
What's Changed
- Added
DropER721_Burn,DropERC1155_BurnBatch,TokenERC721_Burn,TokenERC1155_Burn,TokenERC1155_BurnBatchcontract extensions. - Overriding default RPCs is now allowed through a new
ThirdwebClientcreation parameterrpcOverrides.
var client = ThirdwebClient.Create(
clientId: "myepicclientid",
bundleId: "my.bundle.id", // for native apps
rpcOverrides: new()
{
{ 1, "https://eth.llamarpc.com" },
{ 42161, "https://arbitrum.llamarpc.com" }
}
);- Removed some leftover unnecessary logging.
v2.12.1
What's Changed
- Patch exposing
GetUserDetailsfields when using Ecosystem or In-App Wallets.
v2.12.0
IThirdwebWallet.UnlinkAccount
Adds the ability to Unlink a LinkedAccount from your In-App or Ecosystem Wallet in #107
List<LinkedAccount> linkedAccounts = await inAppWallet.GetLinkedAccounts();
List<LinkedAccount> linkedAccountsAfterUnlinking = await inAppWallet.UnlinkAccount(linkedAccounts[0]);EIP-7702 Integration (Experimental)
Integrates authorizationList for any transactions in #108
This EIP essentially allows you to set code to an EOA, unlocking a world of possibilities to enhance their functionality.
The best way to understand it outside of reading the EIP is looking at the example below; to preface it: we sign an authorization using the wallet we want to set code to. Another wallet sends a transaction with said authorization passed in, essentially activating it. The authority wallet now has code set to it pointing to an (insecure) Delegation contract in this case, which allows any wallet to execute any call through it on behalf of the authority. In this example, we call the wallet executing both the authorization and the claim transaction afterwards, the exectuor.
An authority may execute its own authorization, the only difference is internal whereby the authorization nonce is incremented by 1.
// Chain and contract addresses
var chainWith7702 = 911867;
var erc20ContractAddress = "0xAA462a5BE0fc5214507FDB4fB2474a7d5c69065b"; // Fake ERC20
var delegationContractAddress = "0x654F42b74885EE6803F403f077bc0409f1066c58"; // BatchCallDelegation
// Initialize contracts normally
var erc20Contract = await ThirdwebContract.Create(client: client, address: erc20ContractAddress, chain: chainWith7702);
var delegationContract = await ThirdwebContract.Create(client: client, address: delegationContractAddress, chain: chainWith7702);
// Initialize a (to-be) 7702 EOA
var eoaWallet = await PrivateKeyWallet.Generate(client);
var eoaWalletAddress = await eoaWallet.GetAddress();
Console.WriteLine($"EOA address: {eoaWalletAddress}");
// Initialize another wallet, the "executor" that will hit the eoa's (to-be) execute function
var executorWallet = await PrivateKeyWallet.Generate(client);
var executorWalletAddress = await executorWallet.GetAddress();
Console.WriteLine($"Executor address: {executorWalletAddress}");
// Fund the executor wallet
var fundingWallet = await PrivateKeyWallet.Create(client, privateKey);
var fundingHash = (await fundingWallet.Transfer(chainWith7702, executorWalletAddress, BigInteger.Parse("0.001".ToWei()))).TransactionHash;
Console.WriteLine($"Funded Executor Wallet: {fundingHash}");
// Sign the authorization to make it point to the delegation contract
var authorization = await eoaWallet.SignAuthorization(chainId: chainWith7702, contractAddress: delegationContractAddress, willSelfExecute: false);
Console.WriteLine($"Authorization: {JsonConvert.SerializeObject(authorization, Formatting.Indented)}");
// Execute the delegation
var tx = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: executorWalletAddress, authorization: authorization));
var hash = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx)).TransactionHash;
Console.WriteLine($"Authorization execution transaction hash: {hash}");
// Prove that code has been deployed to the eoa
var rpc = ThirdwebRPC.GetRpcInstance(client, chainWith7702);
var code = await rpc.SendRequestAsync<string>("eth_getCode", eoaWalletAddress, "latest");
Console.WriteLine($"EOA code: {code}");
// Log erc20 balance of executor before the claim
var executorBalanceBefore = await erc20Contract.ERC20_BalanceOf(executorWalletAddress);
Console.WriteLine($"Executor balance before: {executorBalanceBefore}");
// Prepare the claim call
var claimCallData = erc20Contract.CreateCallData(
"claim",
new object[]
{
executorWalletAddress, // receiver
100, // quantity
Constants.NATIVE_TOKEN_ADDRESS, // currency
0, // pricePerToken
new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof
Array.Empty<byte>() // data
}
);
// Embed the claim call in the execute call
var executeCallData = delegationContract.CreateCallData(
method: "execute",
parameters: new object[]
{
new List<Thirdweb.Console.Call>
{
new()
{
Data = claimCallData.HexToBytes(),
To = erc20ContractAddress,
Value = BigInteger.Zero
}
}
}
);
// Execute from the executor wallet targeting the eoa which is pointing to the delegation contract
var tx2 = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData));
var hash2 = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx2)).TransactionHash;
Console.WriteLine($"Token claim transaction hash: {hash2}");
// Log erc20 balance of executor after the claim
var executorBalanceAfter = await erc20Contract.ERC20_BalanceOf(executorWalletAddress);
Console.WriteLine($"Executor balance after: {executorBalanceAfter}");Note that for the time being this only works on 7702-enabled chains such as Odyssey and the feature has only been integrated with PrivateKeyWallet.
EcosystemWallet.GetUserAuthDetails
Adds the ability to retrieve auth provider specific user information from In-App and Ecosystem Wallets in #110
Other additions
SwitchNetworkis now part of the mainIThirdwebWalletinterface. Smart Wallets now attempt to switch the underlying admin network automatically as well.ERC721_TotalSupplyextension now includes burned NFTs when using thirdweb contracts, allowing forERC721_GetAllandERC721_GetOwnedfunctions to return said NFTs as well.- Various new utilities for conversions and transaction decoding, including decoding
authorizationList.
Full Changelog: v2.11.1...v2.12.0