简体   繁体   English

使用 C# 部署 Solidity 合约

[英]deploy solidity contract with c#

I am developing an application on Ethereum blockchain.我正在以太坊区块链上开发一个应用程序。 I use Solidity for contract and Nethereum c# library to connect to the contract.我用密实合同Nethereum C#库连接到了合同。 I am somehow new in Ethereum and it is my first app in blockchain!!我是以太坊的新手,它是我在区块链中的第一个应用程序!! I want to deploy my app in one TESTChain first,我想先在一个TESTChain 中部署我的应用程序,

The problem is that The C# code does not reply anything after send request for deploying of contract.问题是C# 代码在发送部署合约的请求后没有回复任何内容 here is my code这是我的代码

the contract is created well on remix and in running tab it works合同在 remix 上创建得很好,在运行选项卡中它可以工作

  public class DeploymentTest : ContractDeploymentMessage
        {
      public static string BYTECODE = @"0x....";// removed it because of long string

      public DeploymentTest() : base(BYTECODE) { }
        }

      public async Task ConnectToTest()
            {
                var url = "https://github.com/Nethereum/TestChains";
                var pass = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
                var acc = new Account(pass);
                var chain = new Web3(acc, url);
                var deploymentMessage = new DeploymentTest();
                var deploymentHandler =  chain.Eth.GetContractDeploymentHandler<DeploymentTest>();

                 // this point just waited and does not return anything
                var transactionReceipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage);
                var contractAddress = transactionReceipt.ContractAddress;

                }

Can any one help me, I don't insist in deploying with code, it can be happened by anyway but after deploying I need to connect it and call some functions.任何人都可以帮助我,我不坚持用代码部署,无论如何都可能发生,但部署后我需要连接它并调用一些函数。 Thanks谢谢

EDITED已编辑

I downloaded the TESTChain network for windows and it works fine, it seems the default port is 8545 for http:localhost.我下载了 windows 的 TESTChain 网络,它工作正常,似乎 http:localhost 的默认端口是 8545。 but it still does not connect to chain但它仍然没有连接到链

    var web3test = new Web3(); // also tried new Web3(http://localhost:8545);
    var isMining = await web3test.Eth.Mining.IsMining.SendRequestAsync();
    var accounts = await web3test.Eth.Accounts.SendRequestAsync();

is that problem with my connection?我的连接有问题吗? I disabled my MacAfee firewall completely.我完全禁用了我的 MacAfee 防火墙。

在此处输入图片说明

EDITED 2编辑 2

I changed my machine and it works on my another laptop, I cannot find the problem.我更换了我的机器,它可以在我的另一台笔记本电脑上运行,但我找不到问题。 I do not know if I just Uninstall the mcaffe will it be ok or not?我不知道我是否只是卸载 mcaffe 可以吗? has anybody any idea about the firewall prolems or other issues?有人知道防火墙问题或其他问题吗?

I found the problem , it was in my c# code The function which calls the code was on the wait,我发现了问题,是在我的c#代码中调用代码的函数正在等待中,

Main()
{
TestConnection().wait(); // this is not proper 
}

so I changed it to TestConnection(); and it works

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM