首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用类型记录( AptosAccount )创建INVALID_AUTH_KEY

无法使用类型记录( AptosAccount )创建INVALID_AUTH_KEY
EN

Stack Overflow用户
提问于 2022-11-20 19:17:18
回答 3查看 37关注 0票数 1

我正在尝试使用Aptos类型记录SDK创建一个令牌集合。

代码语言:javascript
复制
const account = new AptosAccount(Uint8Array.from(Buffer.from(PRIVATE_KEY)), ACCOUNT_ADDR);

await tokenClient.createCollection(
        account,
        "A test collection 1",
        "A test collection",
        "https://google.com",
    );

但我得到了以下错误:

ApiError2: {"message":"Invalid transaction: Type: Validation Code: INVALID_AUTH_KEY","error_code":"vm_error","vm_error_code":2}

我做错了什么?

尝试复制Aptos的官方例子,但我不创建一个新的帐户,我想使用一个现有的资金帐户。

EN

回答 3

Stack Overflow用户

发布于 2022-11-21 10:59:49

假设您有一个私钥作为十六进制字符串,您可以这样做:

代码语言:javascript
复制
import { AptosAccount, HexString } from "aptos";

const privateKeyHex = "0xdcaf65ead38f7cf0eb4f81961f8fc7f9b7f1e2f45e2d4a6da0dbef85f46f6057";
const privateKeyBytes = HexString.ensure(privateKeyHex).toUint8Array();
const account = new AptosAccount(privateKeyBytes);
票数 2
EN

Stack Overflow用户

发布于 2022-11-24 09:20:53

我也有过同样的问题。最后,我发现问题在于与private_key不匹配的地址,而private_key不是ed25519格式的。您的密钥必须使用ed25519曲线生成,然后您应该根据该键创建您的地址。然后,我使用bip_utils库创建了bip_private_key (使用ed25519协议):

代码语言:javascript
复制
private_key = ed25519.PrivateKey.from_hex(bip_private_key)
票数 0
EN

Stack Overflow用户

发布于 2022-11-29 07:15:34

我只想向Daniel's answer添加一些细节,说明如何在创建钱包之后获得私钥,然后使用它:

代码语言:javascript
复制
import { AptosAccount } from "aptos";

const wallet = new AptosAccount();
const privateKeyHex = wallet.toPrivateKeyObject().privateKeyHex;

// ...

const privateKeyBytes = HexString.ensure(privateKeyHex).toUint8Array();
const account = new AptosAccount(privateKeyBytes);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74511179

复制
相关文章

相似问题

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