Contract-Development
契約部署有效,但方法呼叫失敗
我認為這與我的起跑線有關
geth --datadir ~/final --networkid 98763476 --rpcapi "web3,eth,personal,db,net" --rpcport 888 8 --rpcaddr "ip" --rpccorsdomain "*" --rpc --allow-insecure-unlock
我已經檢查了所需的氣體,所以這不是我可以部署契約的問題,但不能呼叫任何方法我要麼需要氣體,要麼總是失敗的交易或返回的值無效,是否用完了氣體
pragma solidity ^0.5.0; contract Language { function addNumberLanguage(string memory _language) public; } contract Text { address owner; Language language; mapping(string => mapping(string => string)) public texts; constructor(address _language) public { owner = msg.sender; language = Language(_language); } function addText(string memory _language, string memory code, string memory txt) public { require(owner == msg.sender, "Unauthorized"); texts[_language][code] = txt; } function addLanguage(string memory _language) public { require(owner == msg.sender, "Unauthorized"); language.addNumberLanguage(_language); } }
const addText = (language, code, txt, cb) => { contract.methods.addText(language, code, txt).estimateGas({ from: account }).then(gas => { console.log(gas); contract.methods.addText(language, code, txt).send({ from: account, gas: gas }).then(res => cb(true, null)).catch(err => cb(false, err));}).catch(err => cb(false, err)) }
創世紀.json
{ "config": { "chainId": 987, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "0x400", "gasLimit": "0x8000000", "alloc": { "0x41A3BEBcA1475926A7248aeb6b5CA7C43241d473": { "balance": "111111111111111111111111111111" } } }}
將 genesis.json 更改為
{ "config": { "chainId": 9731, "homesteadBlock": 0, "eip150Block": 0, "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "ethash": {} }, "nonce": "0x0", "timestamp": "0x5d5cdc87", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x47b760", "difficulty": "0x80000", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000", "alloc": { "0000000000000000000000000000000000000000": { "balance": "0x1" } }, "number": "0x0", "gasUsed": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" }
一切正常!