c# - 使用 C# 部署 Solidity 合约
问题描述
我正在以太坊区块链上开发一个应用程序。我使用Solidity for contract 和Nethereum c# library 来连接到合约。我是以太坊的新手,这是我在区块链中的第一个应用程序!!我想先在一个TESTChain中部署我的应用程序,
我从 nethereum 网站 Docs ( https://nethereum.readthedocs.io/en/latest/nethereum-smartcontrats-gettingstarted/ )找到了一个私有测试链
创建了我与Remix的简单合同并获得了 ByteCode。
- 编写简单的连接代码来部署和连接到合约。
问题是C# 代码在发送部署合同的请求后没有回复任何内容。这是我的代码
合同在混音上创建得很好,在运行选项卡中它可以工作
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
推荐阅读
- ios - Swift:静音当天的通知
- sas - 有没有办法根据一个值自动创建多个新变量?
- c# - 如何修复C#WPF选项卡悬停颜色以在将选项卡设置为背景自定义颜色时不更改颜色?
- vue.js - Computed Property 导致数组和对象突变
- python - 如何将 groupby 与多索引列一起使用
- r - R中使用汽车数据集的Cor函数
- java - 将字符串解析为 Sql 日期时间
- sql-server - 如何减少 BULK INSERT 中的内存使用量?
- python - 这种二进制排序算法是否需要在内存使用和执行速度方面进行显着优化
- php - 如何验证来自 HTTP 请求的 Google Cloud Task 令牌?