如何從區塊鏈中檢索儲存的數據?
我在區塊鏈中插入了詳細資訊。當我打字
web3.eth.getBlock("latest")
時,difficulty: 2, extraData: "0xd783010802846765746887676f312e372e31856c696e757800000000000000008f438649b8b4382ffd5630c744ccd6db346c8aabce2676a1fdbf752a2ce966b420bc17d8d0f5e31a1212ffad0ac36653e2df29cc14d6bb358b11512762676b0601", gasLimit: 6382057, gasUsed: 2653689, hash: "0xa3dca95fb581a30c1102732b685905ef10a454ec93e8d26171874360821c9055", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0x0000000000000000000000000000000000000000", mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000", nonce: "0x0000000000000000", **number: 16,** parentHash: "0xb9ea05ffc9908313d34a7db976e1b3017a7c9a200ace60445dc7f02d8a610795", receiptsRoot: "0xfd5081c18fec1c7f65a80877425ac186d24713009a519e1659d2a4b2a8166c30", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", size: 10494, stateRoot: "0xe62d1d87c706b650f7e984c9688dc20d1b0a5dd4a7bf05e38e56ca2e63fbfc38", timestamp: 1520398284, totalDifficulty: 33, transactions: ["0x93f9be64f6f5d633298957374748677498dcb57f24ecd9a1c7cf02391e786338"], transactionsRoot: "0xc6c6abb3365c3413fcec7ab62a73ea84d76e17b8d8d2d7c83057d477d08ffaff", uncles: [] }
當我送出數據時,它的數量會增加。
有沒有辦法檢索儲存在區塊鏈中的所有資訊。我不想要雜湊和交易細節。我需要我在使用者界面頁面中輸入的值。
也許使用更高級的東西?像remix一樣,再加上一個本地
testrpc
,你可以從你的合約中訪問數據和呼叫函式。(如果它部署在任何區塊鏈中,您也可以訪問您的合約,它不需要專門的 testrpc)如果你的合約已經部署,將原始碼粘貼到 remix 中,編譯它(
compile
tab, thestart to compile
)然後進入 tab 訪問它,run
在欄位中粘貼你的合約地址,At Address
數據和函式應該出現在底部。然後,您可能需要將 MetaMask 與您的帳戶配對,一旦您
Injected Web3
在該environment
欄位中進行了選擇。
如果你知道交易雜湊,你就可以得到交易。事務還將包含一個具有
input:
. 這將包含您所需的數據,即在該交易中發送的數據web3.eth.getTransaction("0x6556756757ae134....")
您將收到十六進制格式的數據。為了以字元串形式查看您的數據,您需要將其轉換為字元串。您可以使用<https://codebeautify.org/hex-string-converter>
您需要了解您的環境如何將 Solidity 數據轉換為十六進制格式並將其傳輸到合約。此十六進制數據包括參數數量、參數值以及有時參數大小(在動態數據的情況下)的資訊。
例子:
讓我們以這個交易為例: https ://etherscan.io/tx/0x584738783f4e72f49f6c08c5b1f3b7e75c897a70b0a747795294b159aebe2a08
0x362132ad0000000000000000000000000000000000000000000000000000000000000d81000000000000000000000000000000000000000000000000000000000000006066326263376d3672326577000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003
該數據可以解碼如下:
0x362132ad
0000000000000000000000000000000000000000000000000000000000000d8l 0000000000000000000000000000000000000000000000000000000000000060 66326263376d3672326577000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000005 000000000000000000000000000000000000000000000000000000000000000l 000000000000000000000000000000000000000000000000000000000000000l 0000000000000000000000000000000000000000000000000000000000000003 000000000000000000000000000000000000000000000000000000000000000l 0000000000000000000000000000000000000000000000000000000000000003
如果您查看輸入數據,您會看到前 8 個字元是 methodID,然後是發送到該地址的數據。