Example #1
0
        private async Task InitContract()
        {
            var contract = await _blockchainRepository.GetStoredContract(ContractHelpers.ContractName);

            if (contract == null)
            {
                var unlockResult = await _web3.Personal.UnlockAccount.SendRequestAsync(_senderAddress, _password, 120);

                var transactionHash = await _web3.Eth.DeployContract.SendRequestAsync(_abi, _contractByteCode, _senderAddress, new HexBigInteger(900000));

                var receipt = await MineAndGetReceiptAsync(transactionHash);

                var contractAddress = receipt.ContractAddress;

                var contractToSave = new StoredContract
                {
                    Name    = ContractHelpers.ContractName,
                    Address = contractAddress
                };

                await _blockchainRepository.SaveStoredContract(contractToSave);

                _contract = _web3.Eth.GetContract(_abi, contractAddress);
            }
            else
            {
                var contractAddress = contract.Address;
                _contract = _web3.Eth.GetContract(_abi, contractAddress);
            }
        }
Example #2
0
        public async Task SaveStoredContract(StoredContract contract)
        {
            await _context.AddAsync(contract);

            await _context.SaveChangesAsync();
        }