首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有任何方法可以使用dart在ganache服务器上创建帐户?

是否有任何方法可以使用dart在ganache服务器上创建帐户?
EN

Ethereum用户
提问于 2022-10-02 09:13:36
回答 1查看 120关注 0票数 0

我试图创建一个Dapp与颤振,这创建一个区块链帐户使用用户提供的注册细节。我正在尝试使用web3dart包并使用ganache服务器。

EN

回答 1

Ethereum用户

发布于 2022-10-02 11:34:24

首先,您需要连接到本地ganache网络:

代码语言:javascript
复制
import 'package:http/http.dart'; //You can also import the browser version
import 'package:web3dart/web3dart.dart';

var apiUrl = "http://localhost:7545"; //Replace with your API

var httpClient = Client();
var ethClient = Web3Client(apiUrl, httpClient);

在你连接之后,就像和其他网络互动一样。您可以通过以下方式在此网络上创建新凭据:

代码语言:javascript
复制
var rng = Random.secure();
Credentials random = EthPrivateKey.createRandom(rng);

// In either way, the library can derive the public key and the address
// from a private key:
var address = await credentials.extractAddress();
print(address.hex);

这段代码摘自https://pub.dev/documentation/web3dart/latest/

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/136723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档