跳至主要内容
本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)

Multisig Account Key

AccountKeyWeightedMultiSig 是一种账户密钥类型,包含一个阈值和加权公钥(WeightedPublicKeys),后者包含一个由公钥及其权重组成的列表。

要使与 AccountKeyWeightedMultiSig 关联的账户的交易有效,必须满足以下条件: 已签名公钥的加权和应大于阈值。 _ 无效签名不应包含在交易中。 * 已签名公钥的数量应少于加权公钥的数量。

导入 ethers@kaiachain/ethers-ext 软件包,在 ethers.js 上添加 kaia 功能

定义要更改的发件人地址、发件人私人密钥和新的muti-sig 私人密钥

使用指定的 kairos 测试网 URL 设置提供程序。 以太坊中的提供者是访问区块链数据的只读抽象。

此外,您还可以将提供商 URL 从 kairos 更改为 quicknode

私钥提供者创建三个发送者钱包

用新私钥计算公钥

声明一个事务,该事务的字段包含计算出的公钥及其权重,指定类型加权多重签名

与第一个钱包签署交易

与第二个钱包签署交易

在第三个钱包中签署交易,并将其发送至 kaia 网络

如果已在区块链中完成发送,wait函数将返回发送回执。

AccountUpdateWithMultiSigExample.js

const { ethers } = require("ethers");
const { Wallet, TxType, AccountKeyType } = require("@kaiachain/ethers-ext/v6");
// Using same senderNewPriv keys to execute this example repeatedly.
// But you might want to register the different private keys.
const senderAddr = "0x82c6a8d94993d49cfd0c1d30f0f8caa65782cc7e";
const senderNewPriv1 = "0xa32c30608667d43be2d652bede413f12a649dd1be93440878e7f712d51a6768a";
const senderNewPriv2 = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const senderNewPriv3 = "0xc9668ccd35fc20587aa37a48838b48ccc13cf14dd74c8999dd6a480212d5f7ac";
const provider = new ethers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const wallet1 = new Wallet(senderAddr, senderNewPriv1, provider);
const wallet2 = new Wallet(senderAddr, senderNewPriv2, provider);
const wallet3 = new Wallet(senderAddr, senderNewPriv3, provider);
async function main() {
const pub1 = ethers.SigningKey.computePublicKey(senderNewPriv1, true);
const pub2 = ethers.SigningKey.computePublicKey(senderNewPriv2, true);
const pub3 = ethers.SigningKey.computePublicKey(senderNewPriv3, true);
console.log({ pub1, pub2, pub3 });
const tx = {
type: TxType.AccountUpdate,
from: senderAddr,
gasLimit: 1000000,
key: {
type: AccountKeyType.WeightedMultiSig,
threshold: 2,
keys: [
[1, pub1],
[1, pub2],
[1, pub3],
]
}
};
// The example senderAddr actually requires only 2 signature (threshold = 2),
// but we use 3 signatures to show different ways to sign a transaction.
// sign 1: First signer sign from the tx object
const populatedTx = await wallet1.populateTransaction(tx);
const rawTx1 = await wallet1.signTransaction(populatedTx);
console.log("rawTx1", rawTx1);
// sign 2: Middle signer sign from the rawTx
const rawTx2 = await wallet2.signTransaction(rawTx1);
console.log("rawTx2", rawTx2);
// sign 3: Last signer sign and send from the rawTx
const sentTx3 = await wallet3.sendTransaction(rawTx2);
console.log("sentTx3", sentTx3.hash);
const receipt = await sentTx3.wait();
console.log("receipt", receipt);
}
main().catch(console.error);

output

❯ js AccountUpdateWithMultiSigExample.js
{
pub1: '0x021473839f05083617d532325ce8aa40edffb2bc79f1ce17c77cc41f92f027dd82',
pub2: '0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd',
pub3: '0x03f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2a'
}
rawTx1 0x20f8dd74850ba43b7400830f42409482c6a8d94993d49cfd0c1d30f0f8caa65782cc7eb87204f86f02f86ce301a1021473839f05083617d532325ce8aa40edffb2bc79f1ce17c77cc41f92f027dd82e301a103dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cde301a103f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2af847f8458207f6a055fef1ed11853c582a281365fb4f381d2b895758a0436002b6fac3b292594e32a01681d4879eac18d27d20b2dd377cbba4ce723be992ec0fd5e6686645c75c1a3c
rawTx2 0x20f9012474850ba43b7400830f42409482c6a8d94993d49cfd0c1d30f0f8caa65782cc7eb87204f86f02f86ce301a1021473839f05083617d532325ce8aa40edffb2bc79f1ce17c77cc41f92f027dd82e301a103dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cde301a103f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2af88ef8458207f6a055fef1ed11853c582a281365fb4f381d2b895758a0436002b6fac3b292594e32a01681d4879eac18d27d20b2dd377cbba4ce723be992ec0fd5e6686645c75c1a3cf8458207f6a0b445954342f2a9d2b0973f8b36de46e633968c946a9dbbaa3add4f09c91bc0f7a00a72b483157a961d10ed57b6089ee8399018fe5a0f91881375f1b4a0b4fdcf54
sentTx3 0x722b434220cd61c80cf827672bc79006183629399a4f1ad0c98552a47cbb7e07
receipt {
to: '0x82C6a8D94993d49cfd0c1D30F0F8Caa65782cc7E',
from: '0x82C6a8D94993d49cfd0c1D30F0F8Caa65782cc7E',
contractAddress: null,
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0x01b198', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x7e43df2efc735e7c47c163c6ac5ad50c10de542f48cfc5088dfec251b66298c2',
transactionHash: '0x722b434220cd61c80cf827672bc79006183629399a4f1ad0c98552a47cbb7e07',
logs: [],
blockNumber: 152203392,
confirmations: 2,
cumulativeGasUsed: BigNumber { _hex: '0x03ed06', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

让这个页面变得更好