Solidity
set 方法在 Remix 瀏覽器(使用 Test-RPC)中執行良好,但在使用 web3 對象時出現 VM out of gas 錯誤
當我嘗試在混音瀏覽器中使用此呼叫此方法時,它會被探勘。
//addAsset function adds an asset along with an owner function addAsset(address newOwner,bytes32 description, uint cost) returns(string) { if (msg.sender == issuer) { assetCount++; Asset memory tempAsset = Asset(assetCount,newOwner,description,cost); setAssetOwnership(newOwner,assetCount,tempAsset); return "asset created"; } else { return "you are not the owner of contract"; } }
但是當我通過 web3 對像在瀏覽器中呼叫相同的方法時,我得到了這個。
<script> if (typeof web3 !== 'undefined') { var web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); } console.log(web3); web3.eth.defaultAccount = web3.eth.accounts[0]; var vishContract = web3.eth.contract(CONTRACT-OPCODE); //trying to increase the gas limit here, not sure if its correct // var contract = vishContract.at('CONTRACT ADDRESS', {gasLimit: "10000000"}); var contract = vishContract.at('CONTRACT ADDRESS'); function getIssuerId(){ document.getElementById("issuerId").innerText = contract.issuer(); } </script>
我看到發布了類似的問題,其中大多數是通過將字元串更改為 bytes32 來解決的,或者提到他們的契約很大,我的不是。
我對智能合約還是很陌生。任何人都可以在這裡幫助我嗎?
提前致謝 :)
檢查你呼叫合約的賬戶是否有足夠的 ETH。
嘗試在下面使用:
var contract = vishContract.at('CONTRACT ADDRESS', {gas: "10000000"});
代替
var contract = vishContract.at('CONTRACT ADDRESS', {gasLimit: "10000000"});