Skip to content

Commit 3816951

Browse files
committed
Gas price and raw transaction
1 parent 0921ede commit 3816951

7 files changed

Lines changed: 65 additions & 68 deletions

File tree

Packages/com.walletconnect.web3modal/Runtime/Evm/EvmService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ public Task<string> SendTransactionAsync(string addressTo, BigInteger value, str
111111
}
112112

113113

114+
// -- Send Raw Transaction ------------------------------------
115+
116+
public Task<string> SendRawTransactionAsync(string signedTransaction)
117+
{
118+
if (string.IsNullOrWhiteSpace(signedTransaction))
119+
throw new ArgumentNullException(nameof(signedTransaction));
120+
121+
return SendRawTransactionAsyncCore(signedTransaction);
122+
}
123+
124+
114125
// -- Estimate Gas --------------------------------------------
115126

116127
public Task<BigInteger> EstimateGasAsync(string addressTo, BigInteger value, string data = null)
@@ -133,6 +144,14 @@ public Task<BigInteger> EstimateGasAsync(string contractAddress, string contract
133144
return EstimateGasAsyncCore(contractAddress, contractAbi, methodName, value, arguments);
134145
}
135146

147+
148+
// -- Gas Price ------------------------------------------------
149+
150+
public Task<BigInteger> GetGasPriceAsync()
151+
{
152+
return GetGasPriceAsyncCore();
153+
}
154+
136155
protected abstract Task InitializeAsyncCore();
137156
protected abstract Task<BigInteger> GetBalanceAsyncCore(string address);
138157
protected abstract Task<string> SignMessageAsyncCore(string message);
@@ -142,7 +161,9 @@ public Task<BigInteger> EstimateGasAsync(string contractAddress, string contract
142161
protected abstract Task<TReturn> ReadContractAsyncCore<TReturn>(string contractAddress, string contractAbi, string methodName, object[] arguments = null);
143162
protected abstract Task<string> WriteContractAsyncCore(string contractAddress, string contractAbi, string methodName, BigInteger value = default, BigInteger gas = default, params object[] arguments);
144163
protected abstract Task<string> SendTransactionAsyncCore(string addressTo, BigInteger value, string data = null);
164+
protected abstract Task<string> SendRawTransactionAsyncCore(string signedTransaction);
145165
protected abstract Task<BigInteger> EstimateGasAsyncCore(string addressTo, BigInteger value, string data = null);
146166
protected abstract Task<BigInteger> EstimateGasAsyncCore(string contractAddress, string contractAbi, string methodName, BigInteger value = default, params object[] arguments);
167+
protected abstract Task<BigInteger> GetGasPriceAsyncCore();
147168
}
148169
}

Packages/com.walletconnect.web3modal/Runtime/Evm/NethereumEvmService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ protected override Task<string> SendTransactionAsyncCore(string addressTo, BigIn
141141
var transactionInput = new TransactionInput(data, addressTo, new HexBigInteger(value));
142142
return Web3.Client.SendRequestAsync<string>("eth_sendTransaction", null, transactionInput);
143143
}
144+
145+
146+
// -- Send Raw Transaction ------------------------------------
147+
148+
protected override Task<string> SendRawTransactionAsyncCore(string signedTransaction)
149+
{
150+
return Web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(signedTransaction);
151+
}
144152

145153

146154
// -- Estimate Gas ---------------------------------------------
@@ -159,5 +167,14 @@ protected override async Task<BigInteger> EstimateGasAsyncCore(string contractAd
159167
var transactionInput = new TransactionInput(function.GetData(arguments), contractAddress, new HexBigInteger(value));
160168
return await Web3.Eth.Transactions.EstimateGas.SendRequestAsync(transactionInput);
161169
}
170+
171+
172+
// -- Get Gas Price -------------------------------------------
173+
174+
protected override async Task<BigInteger> GetGasPriceAsyncCore()
175+
{
176+
var hexBigInt = await Web3.Eth.GasPrice.SendRequestAsync();
177+
return hexBigInt.Value;
178+
}
162179
}
163180
}

Packages/com.walletconnect.web3modal/Runtime/Evm/WagmiEvmService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ protected override Task<string> SendTransactionAsyncCore(string addressTo, BigIn
5757
return WagmiInterop.SendTransactionAsync(addressTo, value.ToString(), data);
5858
}
5959

60+
protected override Task<string> SendRawTransactionAsyncCore(string signedTransaction)
61+
{
62+
throw new System.NotImplementedException();
63+
}
64+
6065
protected override async Task<BigInteger> EstimateGasAsyncCore(string addressTo, BigInteger value, string data = null)
6166
{
6267
var result = await WagmiInterop.EstimateGasAsync(addressTo, value.ToString(), data);
@@ -70,12 +75,16 @@ protected override async Task<BigInteger> EstimateGasAsyncCore(string contractAd
7075

7176
var functionBuilder = new FunctionBuilder(contractAddress, function);
7277
var data = functionBuilder.GetData(arguments);
73-
74-
Debug.Log($"Wagmi data: {data}");
75-
78+
7679
var result = await WagmiInterop.EstimateGasAsync(contractAddress, value.ToString(), data);
7780
return BigInteger.Parse(result);
7881
}
82+
83+
protected override async Task<BigInteger> GetGasPriceAsyncCore()
84+
{
85+
var result = await WagmiInterop.GetGasPriceAsync();
86+
return BigInteger.Parse(result);
87+
}
7988
}
8089
#endif
8190
}

Packages/com.walletconnect.web3modal/Runtime/WebGL/Wagmi/WagmiInterop.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ public static Task<string> EstimateGasAsync(string to, string value = "0", strin
253253

254254
return InteropCallAsync<EstimateGasParameter, string>(WagmiMethods.EstimateGas, parameter);
255255
}
256+
257+
258+
// -- Get Gas Price -------------------------------------------
259+
260+
public static Task<string> GetGasPriceAsync()
261+
{
262+
return InteropCallAsync<object, string>(WagmiMethods.GetGasPrice, null);
263+
}
256264
}
257265
#endif
258266
}

Samples/AppKit Sample/Assets/Scripts/AppKitInit.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,11 @@ public class AppKitInit : MonoBehaviour
99
{
1010
[SerializeField] private SceneReference _menuScene;
1111

12-
private WalletConnectUnity.Core.Chain currentChain = new WalletConnectUnity.Core.Chain(
13-
chainNamespace: "eip155",
14-
chainReference: "97",
15-
name: "Binance Smart Chain Testnet",
16-
viemName: "bscTestnet",
17-
nativeCurrency: new WalletConnectUnity.Core.Currency
18-
(
19-
"Binance Coin",
20-
"tBNB",
21-
18
22-
),
23-
blockExplorer: new WalletConnectUnity.Core.BlockExplorer
24-
("BscScan", "https://testnet.bscscan.com"),
25-
rpcUrl: "https://data-seed-prebsc-1-s1.bnbchain.org:8545/",
26-
isTestnet: true,
27-
imageUrl: "https://cryptologos.cc/logos/binance-coin-bnb-logo.png" // Example image URL for Binance Coin
28-
);
29-
3012
private async void Start()
3113
{
3214
Debug.Log($"[AppKit Init] Initializing AppKit...");
33-
await Web3Modal.InitializeAsync(new Web3ModalConfig
34-
{
35-
supportedChains = new[]
36-
{
37-
currentChain
38-
}
39-
});
15+
await Web3Modal.InitializeAsync();
4016

41-
// await Web3Modal.InitializeAsync();
42-
4317
var wc = WalletConnectConnector.WalletConnectInstance;
4418
if (wc is { IsInitialized: true })
4519
{

Samples/AppKit Sample/Assets/Scripts/Dapp.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ private void BuildButtons()
8282
}
8383
},
8484
new ButtonStruct
85-
{
86-
Text = "Write Contract",
87-
OnClick = OnWriteContractClicked,
88-
AccountRequired = true
89-
},
90-
new ButtonStruct
9185
{
9286
Text = "Disconnect",
9387
OnClick = OnDisconnectButton,
@@ -366,32 +360,6 @@ public async void OnReadContractClicked()
366360
}
367361
}
368362

369-
public async void OnWriteContractClicked()
370-
{
371-
const string contractAddress = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984";
372-
const string recipientAddress = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
373-
const string abi = @"[{""constant"":false,""inputs"":[{""name"":""to"",""type"":""address""},{""name"":""value"",""type"":""uint256""}],""name"":""transfer"",""outputs"":[{""name"":"""",""type"":""bool""}],""payable"":false,""stateMutability"":""nonpayable"",""type"":""function""}]";
374-
375-
BigInteger amount = 1;
376-
377-
Debug.Log("Let's estimate gas...");
378-
379-
var gas = await Web3Modal.Evm.EstimateGasAsync(contractAddress, abi, "transfer", value: default, recipientAddress, amount);
380-
381-
Debug.Log($"Estimated gas: {gas}");
382-
383-
384-
385-
// // Arguments for the transfer method. The order of the arguments must match the order in the method signature.
386-
// // Method signature: `function transfer(address _to, uint256 _value) public returns (bool success)`
387-
// var arguments = new object[]
388-
// {
389-
// recipientAddress,
390-
// amount
391-
// };
392-
// var result = await Web3Modal.Evm.WriteContractAsync(contractAddress, abi, "transfer", arguments);
393-
}
394-
395363
private TypedData<Domain> GetMailTypedDefinition()
396364
{
397365
return new TypedData<Domain>

Samples/AppKit Sample/Packages/packages-lock.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,17 @@
164164
"depth": 1,
165165
"source": "registry",
166166
"dependencies": {
167-
"com.unity.2d.sprite": "1.0.0",
168167
"com.unity.ugui": "1.0.0",
169-
"com.unity.modules.animation": "1.0.0",
170-
"com.unity.modules.imageconversion": "1.0.0",
168+
"com.unity.2d.sprite": "1.0.0",
169+
"com.unity.modules.ui": "1.0.0",
171170
"com.unity.modules.physics": "1.0.0",
171+
"com.unity.modules.animation": "1.0.0",
172172
"com.unity.modules.physics2d": "1.0.0",
173-
"com.unity.modules.ui": "1.0.0",
174173
"com.unity.modules.uielements": "1.0.0",
174+
"com.unity.modules.imageconversion": "1.0.0",
175175
"com.unity.modules.unitywebrequest": "1.0.0",
176-
"com.unity.modules.unitywebrequesttexture": "1.0.0",
177-
"com.unity.modules.unitywebrequestwww": "1.0.0"
176+
"com.unity.modules.unitywebrequestwww": "1.0.0",
177+
"com.unity.modules.unitywebrequesttexture": "1.0.0"
178178
},
179179
"url": "https://packages.unity.com"
180180
},

0 commit comments

Comments
 (0)