public static async Task DeployLibrary() { // 1. Unclock Account var unlockTime = new HexBigInteger(120); WriteLog($"Unlock account for {unlockTime.Value}s\n" + $" address: {EV.WalletAddress}\n" + $" pass: {EV.WalletPassword}\n\n"); var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync( EV.WalletAddress, EV.WalletPassword, unlockTime); // 2. Deploy library WriteLog("Create transaction to deploy library\n" + $" gas: {_gas.Value}\n" + $" . . . Getting hash . . ."); var transactionHash = await UsersAndFilesService.DeployLibraryAsync(_web3, EV.WalletAddress, _gas); WriteLog($" hash: {transactionHash}"); // 3. Mine transaction WriteLog("\nMine transaction\n" + " . . . Getting receipt . . ."); var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash); WriteLog($" gas used: {receipt.GasUsed.Value}"); EV.LibraryAddress = receipt.ContractAddress; WriteLog($"\n>>> Library Address: {receipt.ContractAddress}"); }
public static async Task DeployContract() { // 1. Unclock Account var unlockTime = new HexBigInteger(120); WriteLog($"Unlock account for {unlockTime.Value}s\n" + $" address: {EV.WalletAddress}\n" + $" pass: {EV.WalletPassword}\n\n"); var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync( EV.WalletAddress, EV.WalletPassword, unlockTime); // 2. Deploy contract // Get contract receipt & contractAddress, save contractAdress to file WriteLog("\nCreate transaction to deploy contract\n" + $" gas: {_gas.Value}\n" + $" library address: {EV.LibraryAddress}"); var adminBytes = new { login = CastHelper.StringToBytes32(admin[0]), password = CastHelper.StringToBytes32(admin[1]), firstName = CastHelper.ToUserNameType(admin[2]), lastName = CastHelper.ToUserNameType(admin[3]), info = CastHelper.ToDescriptionType(admin[4]), }; WriteLog("\n Admin:\n" + $" login: {admin[0]}\n" + $" password: {admin[1]}\n" + $" name: {admin[2]} {admin[3]}\n" + $" info: {admin[4]}"); WriteLog("\n . . . Getting hash . . ."); var transactionHash = await UsersAndFilesService.DeployContractAsync(_web3, EV.LibraryAddress, EV.WalletAddress, adminBytes.login, adminBytes.password, adminBytes.firstName, adminBytes.lastName, adminBytes.info, _gas); WriteLog($" hash: {transactionHash}"); // 3. Mine transaction WriteLog("\nMine transaction\n" + " . . . Getting receipt . . ."); var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash); WriteLog($" gas used: {receipt.GasUsed.Value}"); EV.ContractAddress = receipt.ContractAddress; File.WriteAllText(_output, receipt.ContractAddress); WriteLog("\n>>>\n" + $">>> Contract Address: {receipt.ContractAddress}\n" + ">>>"); }
public async Task T2_DeployContract() { // 1. Unclock Account var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync( SenderAddress, Password, new HexBigInteger(120)); Assert.True(unlockRes); // 2. Deploy contract // Get contract receipt & contractAddress, save contractAdress to file var transactionHash = await UsersAndFilesService.DeployContractAsync(_web3, LibraryAddress, SenderAddress, Stub.AdminLogin, Stub.AdminPassword, Stub.FirstName1, Stub.LastName1, Stub.Info1, Gas); var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash); ContractAddress = receipt.ContractAddress; Assert.True(!string.IsNullOrEmpty(transactionHash)); Assert.NotNull(receipt); }
public async Task T4_GetFileFunction() { _contract = _web3.Eth.GetContract(IpfsFileStorageService.Abi, ContractAddress); _service = new UsersAndFilesService(_web3, ContractAddress); var fileContent = await _service.GetFilePart1AsyncCall( Stub.AdminLogin, Stub.AdminPassword, new BigInteger(1)); Assert.Equal("jpeg", fileContent.MimeType); }
public async Task T1_DeployLibrary() { // 1. Unclock Account var unlockRes = await _web3.Personal.UnlockAccount.SendRequestAsync( SenderAddress, Password, new HexBigInteger(120)); Assert.True(unlockRes); // 2. Deploy library var transactionHash = await UsersAndFilesService.DeployLibraryAsync(_web3, SenderAddress, Gas); var receipt = await UsersAndFilesService.MineAndGetReceiptAsync(_web3, transactionHash); LibraryAddress = receipt.ContractAddress; Assert.True(!string.IsNullOrEmpty(transactionHash)); Assert.NotNull(receipt); }
public EthereumUserService(Web3Geth web3, string address, string walletAddress, BigInteger gas) { _contractService = new UsersAndFilesService(web3, address); _walletAddress = walletAddress; _gas = new HexBigInteger(gas); }