使用Web3 Python的以太坊原始合同互动

发布于 2025-02-07 05:37:05 字数 845 浏览 1 评论 0 原文

我正在寻找合同互动的原始JSON /正文 < / strong> < / strong>它已签署并传递给Web3py / web3js / ethers,

我们正在使用AWS KMS进行钱包设置。这个钱包应该采取一些自动操作。我面临的问题是,为了创建签名,该操作必须以原始格式传递给kms。

我找到了“ nofollow noreferrer”>教程和样本(以太坊本身)从KMS钱包到收件人,所描述的过程是创建一个包含所有必需信息的原始dict,用给定的KMS方法签名,然后将其作为原始事务发布。

例如,简单的交易原始dict应该看起来像这样(EIP-1559之后),

{
    'nonce': nonce,
    'to': 0x0131c121,
    'value': 1000000000000,
    'data': '0x00',
    'gas': 160000,
    'maxFeePerGas': max_fee_per_gas,
    'maxPriorityFeePerGas': max_priority_fee_per_gas,
    'type': type,
    'chainId': chainid,
}

我们试图做的是与需要根据用户操作进行一些更改的各种合同进行交互。我认为应该工作的方式是弄清楚给定合同互动的字典组件的外观。如果有人可以将我指向正确的方向或解释合同互动的原始JSON/身体的样子,那就太好了

I'm looking for an example of a raw json/body of a contract interaction before it is signed and passed to web3py / web3js / ethers

We are using AWS KMS for our wallet setup. There are some automated actions that this wallet is supposed to take. The problem I am facing is that in order to create a signature, the action has to be passed to KMS in a raw format.

I have found tutorials and samples describing the process to transfer a native token (ethereum itself) from the KMS wallet to a recipient, the process described is to create a raw dict containing all the required info, sign it with a given KMS method and then post it as a raw transaction.

For example a simple transaction raw dict should look like this (post EIP-1559)

{
    'nonce': nonce,
    'to': 0x0131c121,
    'value': 1000000000000,
    'data': '0x00',
    'gas': 160000,
    'maxFeePerGas': max_fee_per_gas,
    'maxPriorityFeePerGas': max_priority_fee_per_gas,
    'type': type,
    'chainId': chainid,
}

What we are trying to do, however, is to interact with various contracts that require some changes based on user actions. The way that I believe should work is to figure out what the dictionary body components look like for a given contract interaction. It would be great if someone could point me into the right direction or explain what the raw json/body of a contract interaction looks like

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美羊羊 2025-02-14 05:37:05

实际上比我想象的要简单得多。

{
    'nonce': nonce,
    'to': 0x0131c121,
    'value': 1000000000000,
    'data': '0x00',
    'gas': 160000,
    'maxFeePerGas': max_fee_per_gas,
    'maxPriorityFeePerGas': max_priority_fee_per_gas,
    'type': type,
    'chainId': chainid,
    'data': 0x38ed1739000000000000000000000000000000000000000000000000000000009502f900000000000000000000000000000000000000000000a07e38bf71936cbe39594100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000003c02cebb49f6e8f1fc96158099ffa064bbfee38b00000000000000000000000000000000000000000000000000000000616e11230000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000528b3e98c63ce21c6f680b713918e0f89dfae555
}

data 字段是描述与给定收件人地址(合同)相互作用的原因,并且如以下规格

https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-编码

长话短说,

我只是在web3py上使用了 buildtransaction 函数用给定ABI构建原始事务,因为

tx = usdc.functions.transfer(recipient_address, amount).buildTransaction({'from': signing_address})

USDC是合同的实例。

Actually a lot simpler than I thought.

{
    'nonce': nonce,
    'to': 0x0131c121,
    'value': 1000000000000,
    'data': '0x00',
    'gas': 160000,
    'maxFeePerGas': max_fee_per_gas,
    'maxPriorityFeePerGas': max_priority_fee_per_gas,
    'type': type,
    'chainId': chainid,
    'data': 0x38ed1739000000000000000000000000000000000000000000000000000000009502f900000000000000000000000000000000000000000000a07e38bf71936cbe39594100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000003c02cebb49f6e8f1fc96158099ffa064bbfee38b00000000000000000000000000000000000000000000000000000000616e11230000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000528b3e98c63ce21c6f680b713918e0f89dfae555
}

The data field is what describes the interaction with a given recipient address (which is the contract) and works as described in the following specs

https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-of-the-encoding

Long story short,

I just used the buildTransaction function on web3py to build a raw transaction with the given abi as such

tx = usdc.functions.transfer(recipient_address, amount).buildTransaction({'from': signing_address})

where usdc is an instance of the contract.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文