public async Task <SmartContractDeployResponse> DeployContractAsync(SmartContractDeployRequest request) { Guard.NotNull(request, nameof(request)); var web3 = GetWeb3(request.CallerPrivateKey, request.Endpoint); object[] contractParameters = request.ContractParameters ?? new object[0]; HexBigInteger gas = await web3.Eth.DeployContract.EstimateGasAsync(request.ContractABI, request.ContractByteCode, request.FromAddress, contractParameters); var receipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync( request.ContractABI, request.ContractByteCode, request.FromAddress, gas, null, contractParameters); var entity = new SmartContractEntity { Network = GetNetwork(request.Endpoint), Address = receipt.ContractAddress, NetworkEndpoint = request.Endpoint, ABI = request.ContractABI, ByteCode = request.ContractByteCode, FromAddress = request.FromAddress, GasUsed = (long)receipt.GasUsed.Value, TransactionHash = receipt.TransactionHash }; await _azure.StoreAsync(entity); return(new SmartContractDeployResponse { GasEstimated = (ulong)gas.Value, GasUsed = (ulong)receipt.GasUsed.Value, ContractAddress = receipt.ContractAddress, TransactionHash = receipt.TransactionHash }); }
public async Task <IHttpActionResult> DeploySmartContract([FromBody] SmartContractDeployRequest smartContractDeployRequest) { try { var smartContractDeployedInstanceItem = await this.smartContractManager.DeploySmartContract(smartContractDeployRequest); return(Ok(smartContractDeployedInstanceItem)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <SmartContractDeployedInstanceItem> DeploySmartContract(SmartContractDeployRequest smartContractDeployRequest) { try { var smartContract = await this.smartContractDb.GetSmartContract(smartContractDeployRequest.SmartContractId); var userDltAccount = await this.accountDb.GetUserDltAccountByLoginId(smartContractDeployRequest.DeployByUserLoginId); if (smartContract != null) { var web3 = Nethereum.Geth.Web3Geth("http://localhost:8545/"); //var unlockResult = await } } catch (Exception ex) { } return(null); }
public async Task <SmartContractDeployedInstanceItem> DeploySmartContract(SmartContractDeployRequest smartContractDeployRequest) { try { var smartContract = await this.smartContractDb.GetSmartContract(smartContractDeployRequest.SmartContractId); var userDltAccount = await this.accountDb.GetUserDltAccountByLoginId(smartContractDeployRequest.DeployByUserLoginId); if (smartContract != null) { var web3 = new Web3Geth(); var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(userDltAccount.Address, userDltAccount.PassPhrase, 120); object[] parameters = null; if (smartContractDeployRequest.DeploymentData != null && smartContractDeployRequest.DeploymentData.Count > 0) { parameters = smartContractDeployRequest.DeploymentData.ToArray(); } if (unlockResult) { var gas = await web3.Eth.DeployContract.EstimateGasAsync(smartContract.Abi, smartContract.ByteCode, userDltAccount.Address, parameters); var receipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(smartContract.Abi, smartContract.ByteCode, userDltAccount.Address, gas, null, parameters); string contractAddress = receipt.ContractAddress; SmartContractDeployedInstanceItem deployedInstanceItem = new SmartContractDeployedInstanceItem() { DeployByUserLoginId = smartContractDeployRequest.DeployByUserLoginId, InitialData = Newtonsoft.Json.JsonConvert.SerializeObject(smartContractDeployRequest.DeploymentData), DeployedAddress = contractAddress, SmartContractId = smartContractDeployRequest.SmartContractId, DeployedInstanceDisplayName = smartContractDeployRequest.DeployedInstanceDisplayName }; var mutatedSmartContractDeployedInstanceItem = await this.smartContractDb.CreateSmartContractDeployedInstance(deployedInstanceItem); return(mutatedSmartContractDeployedInstanceItem); } else { throw new Exception("Unable to unlock account"); } } else { throw new Exception("Invalid Smart Contract Id"); } } catch (Exception ex) { this.logger.LogException(ex, "An error occured in method SmartContractManager ==> DeploySmartContract"); throw; } }