Skip to content

Commit 6f37641

Browse files
authored
Add ThirdwebContract.Deploy via new Thirdweb.Api (#155)
1 parent 59d5504 commit 6f37641

File tree

66 files changed

+10239
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+10239
-470
lines changed

.csharpierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.editorconfig

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
11
###############################
2-
# Core EditorConfig Options #
2+
# Core EditorConfig Options #
33
###############################
44

55
root = true
66

77
###############################
8-
# .NET Coding Conventions #
8+
# Generated Code Exclusions #
9+
###############################
10+
11+
# Exclude Thirdweb.Api generated files from all linting and formatting rules
12+
[Thirdweb/Thirdweb.Api/GeneratedClient.cs]
13+
generated_code = true
14+
dotnet_analyzer_diagnostic.severity = none
15+
dotnet_style_qualification_for_field = false
16+
dotnet_style_qualification_for_property = false
17+
dotnet_style_qualification_for_method = false
18+
dotnet_style_qualification_for_event = false
19+
csharp_style_namespace_declarations = block_scoped
20+
dotnet_diagnostic.IDE0130.severity = none
21+
dotnet_diagnostic.IDE0046.severity = none
22+
dotnet_diagnostic.IDE0045.severity = none
23+
dotnet_diagnostic.IDE0066.severity = none
24+
dotnet_diagnostic.IDE0028.severity = none
25+
dotnet_diagnostic.CA1822.severity = none
26+
dotnet_diagnostic.IDE0290.severity = none
27+
# Disable all naming convention rules for generated code
28+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = none
29+
dotnet_naming_rule.public_members_should_be_pascal_case.severity = none
30+
dotnet_naming_rule.private_fields_should_have_underscore_prefix.severity = none
31+
32+
###############################
33+
# Configurable behaviors #
34+
###############################
35+
36+
[*.{cs,csx}]
37+
end_of_line = crlf
38+
indent_style = space
39+
indent_size = 4
40+
max_line_length = 200
41+
42+
###############################
43+
# .NET Coding Conventions #
944
###############################
1045

1146
[*.{cs,vb}]
@@ -148,3 +183,9 @@ dotnet_diagnostic.CA1822.severity = suggestion
148183

149184
# IDE0290: Use primary constructor
150185
dotnet_diagnostic.IDE0290.severity = silent
186+
187+
# JSON002: Probable JSON string detected
188+
dotnet_diagnostic.JSON002.severity = silent
189+
190+
# CS8981: The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
191+
dotnet_diagnostic.CS8981.severity = suggestion

Directory.Build.props

Lines changed: 0 additions & 17 deletions
This file was deleted.

Directory.Packages.props

Lines changed: 0 additions & 26 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

Thirdweb.Console/Program.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,57 @@
11
#pragma warning disable IDE0005
22
#pragma warning disable IDE0059
33

4-
using System.Diagnostics;
5-
using System.Numerics;
6-
using System.Text;
74
using dotenv.net;
8-
using Nethereum.ABI;
9-
using Nethereum.Hex.HexConvertors.Extensions;
10-
using Nethereum.Hex.HexTypes;
11-
using Nethereum.Util;
12-
using Newtonsoft.Json;
13-
using Newtonsoft.Json.Linq;
145
using Thirdweb;
15-
using Thirdweb.AccountAbstraction;
16-
using Thirdweb.AI;
17-
using Thirdweb.Bridge;
18-
using Thirdweb.Indexer;
19-
using Thirdweb.Pay;
206

217
DotEnv.Load();
228

239
// Do not use secret keys client side, use client id/bundle id instead
2410
var secretKey = Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY");
2511

26-
// Do not use private keys client side, use InAppWallet/SmartWallet instead
27-
var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
28-
2912
// Fetch timeout options are optional, default is 120000ms
3013
var client = ThirdwebClient.Create(secretKey: secretKey);
3114

15+
#region Basic Wallet Interaction
16+
3217
// Create a private key wallet
3318
var privateKeyWallet = await PrivateKeyWallet.Generate(client);
3419

35-
// var walletAddress = await privateKeyWallet.GetAddress();
36-
// Console.WriteLine($"PK Wallet address: {walletAddress}");
20+
var walletAddress = await privateKeyWallet.GetAddress();
21+
Console.WriteLine($"PK Wallet address: {walletAddress}");
3722

38-
#region Contract Interaction
23+
#endregion
24+
25+
#region Basic Contract Interaction
3926

4027
// var contract = await ThirdwebContract.Create(client: client, address: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", chain: 1);
4128
// var nfts = await contract.ERC721_GetAllNFTs();
4229
// Console.WriteLine($"NFTs: {JsonConvert.SerializeObject(nfts, Formatting.Indented)}");
4330

4431
#endregion
4532

33+
#region Deploy Contract
34+
35+
// var serverWallet = await ServerWallet.Create(client: client, label: "TestFromDotnet");
36+
37+
// var abi =
38+
// "[ { \"inputs\": [], \"name\": \"welcome\", \"outputs\": [ { \"internalType\": \"string\", \"name\": \"\", \"type\": \"string\" } ], \"stateMutability\": \"pure\", \"type\": \"function\" } ]";
39+
40+
// var contractAddress = await ThirdwebContract.Deploy(
41+
// client: client,
42+
// chainId: 11155111,
43+
// serverWalletAddress: await serverWallet.GetAddress(),
44+
// bytecode: "6080604052348015600e575f5ffd5b5061014e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063b627cf3b1461002d575b5f5ffd5b61003561004b565b60405161004291906100f8565b60405180910390f35b60606040518060400160405280601481526020017f57656c636f6d6520746f20746869726477656221000000000000000000000000815250905090565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6100ca82610088565b6100d48185610092565b93506100e48185602086016100a2565b6100ed816100b0565b840191505092915050565b5f6020820190508181035f83015261011081846100c0565b90509291505056fea264697066735822122001498e9d7d6125ce22613ef32fdb7e8e03bf11ad361d7b00e210b82d7b7e0d4464736f6c634300081e0033",
45+
// abi: abi
46+
// );
47+
// Console.WriteLine($"Contract deployed at: {contractAddress}");
48+
49+
// var contract = await ThirdwebContract.Create(client: client, address: contractAddress, chain: 11155111, abi: abi);
50+
// var welcomeMessage = await contract.Read<string>("welcome");
51+
// Console.WriteLine($"Welcome message from deployed contract: {welcomeMessage}");
52+
53+
#endregion
54+
4655
#region Bridge
4756

4857
// // Create a ThirdwebBridge instance
@@ -325,18 +334,11 @@
325334

326335
#region AA ZkSync
327336

328-
// var zkSmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 4654, gasless: true);
337+
var zkSmartWallet = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 11124, gasless: true);
329338

330-
// var hash = await zkSmartWallet.SendTransaction(
331-
// new ThirdwebTransactionInput(4654)
332-
// {
333-
// To = await zkSmartWallet.GetAddress(),
334-
// Value = new HexBigInteger(BigInteger.Zero),
335-
// Data = "0x",
336-
// }
337-
// );
339+
var hash = await zkSmartWallet.SendTransaction(new ThirdwebTransactionInput(chainId: 11124, to: await zkSmartWallet.GetAddress(), value: 0, data: "0x"));
338340

339-
// Console.WriteLine($"Transaction hash: {hash}");
341+
Console.WriteLine($"Transaction hash: {hash}");
340342

341343
#endregion
342344

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
42
<PropertyGroup>
53
<OutputType>Exe</OutputType>
64
<TargetFramework>net8.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<Nullable>enable</Nullable>
99
<IsPackable>false</IsPackable>
1010
</PropertyGroup>
11-
1211
<ItemGroup>
1312
<ProjectReference Include="..\Thirdweb\Thirdweb.csproj" />
1413
</ItemGroup>
15-
1614
<ItemGroup>
17-
<PackageReference Include="dotenv.net" />
15+
<PackageReference Include="dotenv.net" Version="3.1.3" />
1816
</ItemGroup>
19-
2017
<ItemGroup>
2118
<None Update=".env">
2219
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2320
</None>
2421
</ItemGroup>
25-
26-
</Project>
22+
</Project>

Thirdweb.Tests/Thirdweb.Contracts/Thirdweb.Contracts.Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public async Task SignatureMint_Generate()
228228
Value = BigInteger.Zero,
229229
Gas = BigInteger.Zero,
230230
Nonce = BigInteger.Zero,
231-
Data = "0x"
231+
Data = "0x",
232232
};
233233
var signature = await EIP712.GenerateSignature_MinimalForwarder(randomDomain, randomVersion, randomChainId, randomContractAddress, forwardRequest, signer);
234234
Assert.NotNull(signature);
@@ -243,7 +243,7 @@ public async Task SignatureMint_Generate()
243243
Currency = Constants.ADDRESS_ZERO,
244244
ValidityEndTimestamp = 0,
245245
ValidityStartTimestamp = Utils.GetUnixTimeStampIn10Years(),
246-
Uid = new byte[] { 0x01 }
246+
Uid = new byte[] { 0x01 },
247247
};
248248
var signature20 = await EIP712.GenerateSignature_TokenERC20(randomDomain, randomVersion, randomChainId, randomContractAddress, mintRequest20, signer);
249249
Assert.NotNull(signature20);
@@ -261,7 +261,7 @@ public async Task SignatureMint_Generate()
261261
Currency = Constants.ADDRESS_ZERO,
262262
ValidityEndTimestamp = 0,
263263
ValidityStartTimestamp = Utils.GetUnixTimeStampIn10Years(),
264-
Uid = new byte[] { 0x01 }
264+
Uid = new byte[] { 0x01 },
265265
};
266266
var signature721 = await EIP712.GenerateSignature_TokenERC721(randomDomain, randomVersion, randomChainId, randomContractAddress, mintRequest721, signer);
267267
Assert.NotNull(signature721);
@@ -281,7 +281,7 @@ public async Task SignatureMint_Generate()
281281
Currency = Constants.ADDRESS_ZERO,
282282
ValidityEndTimestamp = 0,
283283
ValidityStartTimestamp = Utils.GetUnixTimeStampIn10Years(),
284-
Uid = new byte[] { 0x01 }
284+
Uid = new byte[] { 0x01 },
285285
};
286286
var signature1155 = await EIP712.GenerateSignature_TokenERC1155(randomDomain, randomVersion, randomChainId, randomContractAddress, mintRequest1155, signer);
287287
Assert.NotNull(signature1155);

0 commit comments

Comments
 (0)