我可以在智能合约中调用任何API来通过txid获取交易明细吗?

时间:2019-03-31 13:38:15

标签: ethereum smartcontracts

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

2 个答案:

答案 0 :(得分:1)

我认为您想在智能合约中调用类似getTransaction的RPC调用。但是,那是不可能的。

所有可在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/

总而言之,对于您的问题,以本机方式无法通过可靠性获取交易详细信息,您应该使用Oraclize等脱链解决方案。 :)

答案 1 :(得分:1)

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