[英]deploy solidity contract with c#
我正在以太坊区块链上开发一个应用程序。 我用密实合同Nethereum C#库连接到了合同。 我是以太坊的新手,它是我在区块链中的第一个应用程序!! 我想先在一个TESTChain 中部署我的应用程序,
我从 nethereum 网站 Docs ( https://nethereum.readthedocs.io/en/latest/nethereum-smartcontrats-gettingstarted/ ) 找到了一个私有测试链
与Remix创建了我的简单合同并获得了 ByteCode。
问题是C# 代码在发送部署合约的请求后没有回复任何内容。 这是我的代码
合同在 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;
}
任何人都可以帮助我,我不坚持用代码部署,无论如何都可能发生,但部署后我需要连接它并调用一些函数。 谢谢
已编辑
我下载了 windows 的 TESTChain 网络,它工作正常,似乎 http:localhost 的默认端口是 8545。 但它仍然没有连接到链
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();
我的连接有问题吗? 我完全禁用了我的 MacAfee 防火墙。
编辑 2
我更换了我的机器,它可以在我的另一台笔记本电脑上运行,但我找不到问题。 我不知道我是否只是卸载 mcaffe 可以吗? 有人知道防火墙问题或其他问题吗?
我发现了问题,是在我的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.