如何解决使用 dart 在基于以太坊的 Cleo 测试网中发布智能合约
我正在尝试使用 dart 在 Celo alfajores testnet 中部署智能合约。我在“HelloWorld.json”中提取了一个智能合约的最小 abi,它也包含字节码。我已经创建了一个地址并使用水龙头为地址添加了余额。现在我想使用 dart 部署合约。我正在使用 web3dart library。这是我的代码:
import 'dart:typed_data';
import 'dart:io';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'package:path/path.dart' show join,dirname;
import 'dart:convert';
final File abiFile = File('HelloWorld.json');
void main(List<String> arguments) async {
print("test");
final abiCode = await abiFile.readAsstring();
final jsonResponse = jsonDecode(abiCode);
print(jsonResponse["bytecode"]);
var rpcUrl =
"https://alfajores-forno.celo-testnet.org"; //Replace with your API
final client = Web3Client(rpcUrl,Client());
final credentials = await client.credentialsFromPrivateKey(
"0x20498351837bf81dd55a5dcc598b08c93b44b0202ccd9d1b6ccbb509a027a35f");
final address = await credentials.extractAddress();
print(address);
print(await client.getBalance(address));
List<int> list = utf8.encode(jsonResponse["bytecode"]);
Uint8List bytes = Uint8List.fromList(list);
await client.sendTransaction(
credentials,Transaction(
from: address,data: bytes),);
}
如何解决此问题并部署合约?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。