public async Task <bool> ShouldSignAndSendRawTransaction() { var receiveAddress = "0x13f022d72158410433cbd66f5dd8bf6d2d129924"; var web3 = _ethereumClientIntegrationFixture.GetWeb3(); var feeStrategy = new SimpleFeeSuggestionStrategy(web3.Client); var fee = await feeStrategy.SuggestFeeAsync(); var encoded = await web3.TransactionManager.SignTransactionAsync( new TransactionInput() { Type = new HexBigInteger(2), From = web3.TransactionManager.Account.Address, MaxFeePerGas = new HexBigInteger(fee.MaxFeePerGas.Value), MaxPriorityFeePerGas = new HexBigInteger(fee.MaxPriorityFeePerGas.Value), Nonce = await web3.Eth.TransactionManager.Account.NonceService.GetNextNonceAsync(), To = receiveAddress, Value = new HexBigInteger(10) }); Assert.True(TransactionVerificationAndRecovery.VerifyTransaction(encoded)); Assert.Equal(web3.TransactionManager.Account.Address.EnsureHexPrefix().ToLower(), TransactionVerificationAndRecovery.GetSenderAddress(encoded).EnsureHexPrefix().ToLower()); var txId = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded); var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId); while (receipt == null) { Thread.Sleep(1000); receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId); } Assert.Equal(txId, receipt.TransactionHash); return(true); }
static void Main(string[] args) { //var credential = new DefaultAzureCredential( // new DefaultAzureCredentialOptions // { // //VisualStudioTenantId = TENANT_ID, // //VisualStudioCodeTenantId = TENANT_ID, // }); var credential = new ClientSecretCredential(TENANT_ID, APP_ID, APP_PASSWORD); var signer = new AzureKeyVaultExternalSigner(KEY_NAME, URI, credential); var address = signer.GetAddressAsync().Result; System.Console.WriteLine(address); var msgHash = new Util.Sha3Keccack().CalculateHash("Hello").HexToByteArray(); var signature = signer.SignAsync(msgHash).Result; var publicKeyRecovered = EthECKey.RecoverFromSignature(signature, msgHash); System.Console.WriteLine(publicKeyRecovered.GetPubKey().ToHex()); var transfer = new TransferFunction(); transfer.To = "0x1996a57077877D38e18A1BE44A55100D77b8fA1D"; transfer.FromAddress = publicKeyRecovered.GetPublicAddress(); transfer.Value = 1; transfer.Nonce = 1; transfer.GasPrice = 100; transfer.Gas = 1000; var rpcClient = new RpcClient(new Uri("http://localhost:8545")); var transactionInput = transfer.CreateTransactionInput("0x12890d2cce102216644c59daE5baed380d84830c"); var externalAccount = new ExternalAccount(signer, 1); externalAccount.InitialiseAsync().Wait(); externalAccount.InitialiseDefaultTransactionManager(rpcClient); var signature2 = externalAccount.TransactionManager.SignTransactionAsync(transactionInput).Result; var publicKeyRecovered2 = TransactionVerificationAndRecovery.GetPublicKey(signature2); var transactionFromSignature = TransactionFactory.CreateTransaction(signature2); System.Console.WriteLine("Recovered public key"); System.Console.WriteLine(publicKeyRecovered2.ToHex()); System.Console.WriteLine("Recovered transaction Type"); System.Console.WriteLine(transactionFromSignature.TransactionType.ToString()); System.Console.WriteLine("Signing EIP1559"); var transferEip1559 = new TransferFunction(); transferEip1559.To = "0x1996a57077877D38e18A1BE44A55100D77b8fA1D"; transferEip1559.FromAddress = publicKeyRecovered.GetPublicAddress(); transferEip1559.Value = 1; transferEip1559.Nonce = 1; transferEip1559.MaxFeePerGas = 1000; transferEip1559.MaxPriorityFeePerGas = 999; transferEip1559.Gas = 1000; var transactionInputEip1559 = transferEip1559.CreateTransactionInput("0x12890d2cce102216644c59daE5baed380d84830c"); var signature3 = externalAccount.TransactionManager.SignTransactionAsync(transactionInputEip1559).Result; var publicKeyRecovered3 = TransactionVerificationAndRecovery.GetPublicKey(signature3); var transactionFromSignatureEIP1559 = TransactionFactory.CreateTransaction(signature3); System.Console.WriteLine("Recovered public key"); System.Console.WriteLine(publicKeyRecovered3.ToHex()); System.Console.WriteLine("Recovered transaction Type"); System.Console.WriteLine(transactionFromSignatureEIP1559.TransactionType.ToString()); System.Console.ReadLine(); }