【问题标题】:Is there any API that I can call inside of the smartcontract that can get a transaction detail by txid?我可以在智能合约内部调用任何可以通过 txid 获取交易详细信息的 API 吗?
【发布时间】:2019-03-31 13:38:15
【问题描述】:

我正在学习以太坊开发,想在智能合约中通过txid查看交易细节,但是我没有找到任何可以帮助我做到这一点的接口,有人有任何线索吗?

【问题讨论】:

    标签: ethereum smartcontracts


    【解决方案1】:

    我想你想在智能合约中调用getTransaction-like RPC call。但是,这是不可能的。

    所有可以在 Solidity 中使用的全局变量如下。

    Global Variables
    
    block.coinbase (address): current block miner’s address
    block.difficulty (uint): current block difficulty
    block.gaslimit (uint): current block gaslimit
    block.number (uint): current block number
    block.blockhash (function(uint) returns (bytes32)): hash of the given block - only works for 256 most recent blocks
    block.timestamp (uint): current block timestamp
    msg.data (bytes): complete calldata
    msg.gas (uint): remaining gas
    msg.sender (address): sender of the message (current call)
    msg.value (uint): number of wei sent with the message
    now (uint): current block timestamp (alias for block.timestamp)
    tx.gasprice (uint): gas price of the transaction
    tx.origin (address): sender of the transaction (full call chain)
    sha3(...) returns (bytes32): compute the Ethereum-SHA3 hash of the (tightly packed) arguments
    sha256(...) returns (bytes32): compute the SHA256 hash of the (tightly packed) arguments
    ripemd160(...) returns (bytes20): compute RIPEMD of 256 the (tightly packed) arguments
    ecrecover(bytes32, uint8, bytes32, bytes32) returns (address): recover public key from elliptic curve signature
    addmod(uint x, uint y, uint k) returns (uint): compute (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2**256.
    mulmod(uint x, uint y, uint k) returns (uint): compute (x * y) % k where the multiplication is performed with arbitrary precision and does not wrap around at 2**256.
    this (current contract’s type): the current contract, explicitly convertible to address
    super: the contract one level higher in the inheritance hierarchy
    selfdestruct(address): destroy the current contract, sending its funds to the given address
    .balance: balance of the address in Wei
    .send(uint256) returns (bool): send given amount of Wei to address, returns false on failure.
    

    当然,使用 Oraclize 有一些棘手的解决方案。 我推荐看看这个网站:) https://docs.oraclize.it/

    总之,对于您的问题,以本机方式无法从solidity 获取交易详细信息,您应该使用Oraclize 之类的链下解决方案。 :)

    【讨论】:

      【解决方案2】:

      智能合约只能访问区块链的当前状态。 Solidity 仅用于为事务创建规则并更新变量的状态。要获得交易,您必须使用 web3 库。

      【讨论】:

        猜你喜欢
        • 2018-11-30
        • 1970-01-01
        • 2021-12-30
        • 2021-10-18
        • 2016-01-26
        • 2019-01-17
        • 2022-12-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多