Go-Ethereum

Geth 得到部署的合約

  • September 1, 2016

我是區塊鏈的新手,到目前為止,我已經設法通過 geth 控制台和節點程式碼部署合約並傳輸乙太幣……我現在正試圖弄清楚如何獲取我已經部署的合約並通過它與之互動Geth 和 javascript …我將不勝感激。

謝謝!:)

這是您需要的主要步驟的範例。您需要 ABI(從您編譯契約時開始)和您部署到的地址。

https://github.com/ethereum/wiki/wiki/JavaScript-API#example-50

// contract abi
var abi = [{
    name: 'myConstantMethod',
    type: 'function',
    constant: true,
    inputs: [{ name: 'a', type: 'string' }],
    outputs: [{name: 'd', type: 'string' }]
}, {
    name: 'myStateChangingMethod',
    type: 'function',
    constant: false,
    inputs: [{ name: 'a', type: 'string' }, { name: 'b', type: 'int' }],
    outputs: []
}, {
    name: 'myEvent',
    type: 'event',
    inputs: [{name: 'a', type: 'int', indexed: true},{name: 'b', type: 'bool', indexed: false}]
}];

// creation of contract object
var MyContract = web3.eth.contract(abi);

// initiate contract for an address
var myContractInstance = MyContract.at('0xc4abd0339eb8d57087278718986382264244252f');

// call constant function
var result = myContractInstance.myConstantMethod('myParam');
console.log(result) // '0x25434534534'

引用自:https://ethereum.stackexchange.com/questions/8458