本文へスキップ
このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。Crowdinでの取り組みに参加して、このページの翻訳改善にご協力ください。 (Crowdin translation page, Contributing guide)

マルチシグ・アカウント・キー

AccountKeyWeightedMultiSigは、閾値とWeightedPublicKeys(公開鍵とその重みからなるリスト)を含むアカウント鍵タイプである。

AccountKeyWeightedMultiSigに関連付けられたアカウントで取引が有効であるためには、 以下の条件を満たす必要がある: 署名された公開鍵の加重和が閾値より大きいこと。 無効な署名はトランザクションに含めるべきでない。 * 署名された公開鍵の数は、weightedPublicKeysの数より少なくなければならない。

web3をkaia web3に拡張するために、web3py_extからextendをインポートする。

必要なutilsをweb3web3py_extからインポートする。

指定されたkairosテストネットURLでWeb3インスタンスを作成する

また、プロバイダーのURLをkairosからquicknodeに変更することもできます。

Account.from_keyを使用して3つの異なるアカウントを定義する。

TxType.ACCOUNT_UPDATE型の空のトランザクションを作成しています。 empty_txユーティリティを使えば、デフォルトのフィールドが埋められたtxを得ることができる。

mergeユーティリティを使用して、senderkeysのような追加フィールドを空のtxにマージする。

この場合、更新するアカウント・キーはmutisigキーであり、中の各キーは圧縮された公開キーとそのウェイトを含む。 compressed_keyユーティリティは、圧縮された公開鍵を鍵から抽出する。

fill_transactionを使用して、トランザクション・オブジェクトにガス・リミットなどのパラメータを追加する。

to_prettyユーティリティを使えば、フォーマットされたtxをプリントすることができる。

アカウント更新TXタイプに署名する。 ロードした3個のアカウントすべてで署名する必要があります

**署名されたトランザクションをネットワークに送信し、ブロックチェーンで完全に実行されるまで受信を待つ。

web3_account_update_multisig.py

from web3py_ext import extend
from web3 import Web3
from eth_account import Account
from web3py_ext.klaytn_account.utils import compressed_key
from web3py_ext.klaytn_account.account_key import KeyType
from web3py_ext.transaction.transaction import (
empty_tx,
fill_transaction,
TxType
)
from web3py_ext.utils.klaytn_utils import (
to_pretty,
bytes_to_hex_str
)
from cytoolz import merge
w3 = Web3(Web3.HTTPProvider(
'https://public-en-kairos.node.kaia.io'
))
def web3_account_update_multisig():
user1 = Account.from_key("0xa32c30608667d43be2d652bede413f12a649dd1be93440878e7f712d51a6768a")
user2 = Account.from_key("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8")
user3 = Account.from_key("0xc9668ccd35fc20587aa37a48838b48ccc13cf14dd74c8999dd6a480212d5f7ac")
account_update_tx = empty_tx(TxType.ACCOUNT_UPDATE)
account_update_tx = merge(account_update_tx, {
'from' : user1.address, #0x82c6a8d94993d49cfd0c1d30f0f8caa65782cc7e
'key' : {
'type': KeyType.MULTISIG,
'threshold': 2,
'keys': [
{
'weight':1,
'key': compressed_key(user1),
},
{
'weight':1,
'key': compressed_key(user2),
},
{
'weight':1,
'key': compressed_key(user3),
},
]
}
})
account_update_tx = fill_transaction(account_update_tx, w3)
print(to_pretty(account_update_tx))
# sign the kaia specific transaction type with web3py
signed_tx = Account.sign_transaction(account_update_tx, user1.key)
signed_tx = Account.sign_transaction(signed_tx.rawTransaction, user2.key)
signed_tx = Account.sign_transaction(signed_tx.rawTransaction, user3.key)
print('\nrawTransaction:', bytes_to_hex_str(signed_tx.rawTransaction))
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print('tx hash: ', tx_hash, 'receipt: ', tx_receipt)
web3_account_update_multisig()

output

❯ web3_account_update_multisig.py
{
"from":"0x82C6a8D94993d49cfd0c1D30F0F8Caa65782cc7E",
"gas":159000,
"gasPrice":50000000000,
"nonce":103,
"chainId":1001,
"type":32,
"key":{
"type":4,
"threshold":2,
"keys":[
{
"weight":1,
"key":"0x021473839f05083617d532325ce8aa40edffb2bc79f1ce17c77cc41f92f027dd82"
},
{
"weight":1,
"key":"0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd"
},
{
"weight":1,
"key":"0x03f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2a"
}.
]
}
}
rawTransaction:20f9016b67850ba43b740083026d189482c6a8d94993d49cfd0c1d30f0f8caa65782cc7eb87204f86f02f86ce301a1021473839f05083617d532325ce8aa40edffb2bc79f1ce17c77cc41f92f027dd82e301a103dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cde301a103f26489914098c5da51f0f646e3000da4d6197217df082b4f7ce1530f0a0cbf2af8d5f8458207f6a0978b0c4dcfb9dfd4351842463519f7913a9653bb3954fde04e8c81b59c5f0138a04384e1e3436a43d165f4a03cac64f4a60fbd237d7473f58016bda5381c33a1d2f8458207f6a0431be32222e5dea7d4126254fea9784f9b55171948506477b876995cf04e8185a06d755a79656a7e32f179548e00e314bc37c78d67918b89abc7390083a64c91dcf8458207f5a0c4bc3a38652ede87c9c1f7057b63c9d4ae1bb694d722c36b6901b4ec0b258dbca02559cae1ebcf3baa23a9cbe6fddb81d652f44636534cc9214c26d6127be5b849
txハッシュ 0x0774fac9bc9f1b49b4fb4b7a9af87fef52f298e2cbdeb61491eab7bdc401758d receipt: AttributeDict({'blockHash':HexBytes('0xd15a2095f70243121b427aeeebb507937c8bc808526bfa5990806a12df8a3d6f'), 'blockNumber':150554112, 'contractAddress':なし, 'cumulativeGasUsed': 111000, 'effectiveGasPrice': 25000000000, 'from': '0x82C6a8D94993d49cfd0c1D30F0F8Caa65782cc7E', 'gasUsed': 111000, 'logs': [], 'logsBloom':HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),'status':1, 'to': '0x82C6a8D94993d49cfd0c1D30F0F8Caa65782cc7E', 'transactionHash':HexBytes('0x0774fac9bc9f1b49b4fb4b7a9af87fef52f298e2cbdeb61491eab7bdc401758d'), 'transactionIndex':0, 'type': 0})

ページを改善してください。