简体   繁体   English

如何调用智能合约 function. python web3

[英]how to call smart contract function. python web3

https://polygonscan.com/tx/0x0a37f5af0aa5b15431e339a7dc4ce3bdc77f229e8bd69025a4740812e0c55e6f https://polygonscan.com/tx/0x0a37f5af0aa5b15431e339a7dc4ce3bdc77f229e8bd69025a4740812e0c55e6f

the transaction name that appears in the metamaks is collect_from_tiles.出现在 metamak 中的事务名称是 collect_from_tiles。

looking for this function in the contract.在合同中寻找这个function。 I noticed that she is in another contract.我注意到她在另一份合同中。 https://polygonscan.com/address/0x068adc06faff086ee9ef826c0b83e7710e223c3d#writeContract https://polygonscan.com/address/0x068adc06faff086ee9ef826c0b83e7710e223c3d#writeContract

how to find out which values to pass?如何找出要传递的值? Is there any tool to catch traffic when confirming in the metamask or something?在元掩码中确认时是否有任何工具可以捕获流量?

every transaction I go through.每笔交易我go通过。 hangs until it fails.挂起直到失败。


def get_token_abi(token):
    url = f'https://api.polygonscan.com/api?module=contract&action=getabi&address={token}'
    response = requests.get(url).json()
    return json.loads(response['result'])

    tiles = [(-1, 1, 0), (-1, 0, 1), (0, -1, 1), (1, 0, -1), (0, 1, -1)]
    v = ?
    r = ?
    s = ?

    tx_collector = contract_collect.functions.collectFromTiles(tiles, v, r, s).build_transaction({
        'type': '0x2',
        'gas': 361075,
        'maxFeePerGas': 35000000000,
        'maxPriorityFeePerGas': 35000000000,
        'chainId': 137,
        'nonce': nonce,
    })

enter image description here在此处输入图像描述

enter image description here在此处输入图像描述

how to find out the parameters that are passed in the transaction time?如何找出交易时间传递的参数?

Going through the contract's source code itself, you can see that on line 223 of MissionControl.sol , a checkSignature method is called.查看合约的源代码本身,您可以看到在MissionControl.sol的第 223 行,调用了一个checkSignature方法。 This signature is referring to ECDSA's signature algorithm.这个签名是指ECDSA的签名算法。 In which you can look into more detail in this article and this forum thread .您可以在本文和此论坛主题中查看更多详细信息。

Long story short, you have to use this algorithm to sign some input (perhaps just the tiles itself or a specific message), and then pass the signature as an r, s, and v format.长话短说,您必须使用此算法对某些输入(可能只是磁贴本身或特定消息)进行签名,然后将签名作为 r、s 和 v 格式传递。

In order to do that you also need an ECDSA keys (private and public) and sign the message with the private key.为此,您还需要一个 ECDSA 密钥(私钥和公钥)并使用私钥对消息进行签名。 This is basically a way to prove that you are really the person you are supposed to be.这基本上是一种证明你真的是你应该成为的人的方法。

PS I am not sure if any generated ECDSA key pair works (as in they just check the message integrity rather than authenticating the user) or it has to be the one that corresponds to the public key on the contract. PS 我不确定是否有任何生成的 ECDSA 密钥对有效(因为它们只是检查消息完整性而不是对用户进行身份验证)或者它必须是与合同上的公钥相对应的密钥对。 It very much depends on what the use case here.这在很大程度上取决于这里的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM