问题描述
我正在尝试使用 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 (将#修改为@)