사소한 질문입니다. 계약서를 배포하려면 어떻게해야합니까?내 네트워크에 HelloWorld 계약을 배포 할 수 없습니다. (testrpc)
pragma solidity ^0.4.17;
contract HelloWorld{
function sayHello() internal pure returns(string){
return("Hello 2018!");
}
}
초기 migrations.js : 내가 가지고있는
는 로 정의 간단한 안녕하세요 계약는 HelloWorld.sol 다음
var Migrations = artifacts.require("./Migrations.sol");
var HelloWorld = artifacts.require("./HelloWorld.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
deployer.deploy(HelloWorld);
};
그리고를 마지막으로 이후 메신저 사용 송로 버섯, truffle.js :
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};
나는 명령을 실행
truffle compile
truffle migrate
그런 다음 콘솔로 이동 :
truffle console
그리고 난 JS 사용
var hw
HelloWorld.deployed().then(function(deployed){hw=deployed;});
내가 어떻게 올바르게 배포하는
Error: HelloWorld has not been deployed to detected network (network/artifact mismatch) at C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:317116:17 at at process._tickDomainCallback (internal/process/next_tick.js:228:7)
를 얻을 수를 내 계약과 테스트 에돔?
나는 또한 내 testrpc 서버가 8545에서 실행 중이고 모든 것이 정상적으로 작동한다고 추가해야합니다. (이것 모두는 localhost에서 실행 중입니다.) 네트워크의 ID를 지정하려고했습니다. 명시 적으로 ID를 설정하고 truffle.js에 지정했지만 여전히 작동하지 않습니다. 또한 함수의 가시성을 변경하려고했습니다.
콘솔 출력 흔적 원하는 결과에 :
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle compile
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate
Using network 'development'.
Network up to date.
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle console
truffle(development)> var hw
undefined
truffle(development)> HelloWorld.deployed().then(function(deployed){hw=deployed;});
undefined
truffle(development)> hw.sayHello.call()
''
truffle(development)> hw.SayHello.call()
TypeError: Cannot read property 'call' of undefined
at evalmachine.<anonymous>:1:13
at ContextifyScript.Script.runInContext (vm.js:59:29)
at Object.runInContext (vm.js:120:6)
at Console.interpret (C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:202629:17)
at ReplManager.interpret (C:\Users\Kofola\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:203345:18)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:441:10)
at emitOne (events.js:116:13)
at REPLServer.emit (events.js:211:7)
truffle(development)> hw.sayHello.call()
''
truffle(development)> .exit
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate --reset
Could not connect to your Ethereum client. Please check that your Ethereum client:
- is running
- is accepting RPC connections (i.e., "--rpc" option is used in geth)
- is accessible over the network
- is properly configured in your Truffle configuration file (truffle.js)
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle compile
Compiling .\contracts\HelloWorld.sol...
Compiling .\contracts\Migrations.sol...
Compilation warnings encountered:
/C/Users/Kofola/BlockChain/EthereumHelloWorld/contracts/HelloWorld.sol:5:5: Warning: No visibility specified. Defaulting to "public".
function sayHello() returns(string){
^
Spanning multiple lines.
,/C/Users/Kofola/BlockChain/EthereumHelloWorld/contracts/HelloWorld.sol:5:5: Warning: Function state mutability can be restricted to pure
function sayHello() returns(string){
^
Spanning multiple lines.
Writing artifacts to .\build\contracts
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate --reset
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0x1ed08bc4bcbb9db244acd9edfe4cfc71ca1675d069e4f17dcb5780f1ae496da0
Migrations: 0x2bcb6d8aade2239b14c17374d631be59c2847175
Deploying HelloWorld...
... 0x0195732cdb2a7fae8896be02a86403c88fd45c5e793a0ab1de7b3fdf6a086a67
HelloWorld: 0xf169c021288e56a0b9739fd959fe305a7f67f500
Saving successful migration to network...
... 0xed919bb06a5a83fbf7e8bae8b99ec2f398979b51bc3f41c152ef621e1c799561
Saving artifacts...
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle migrate
Using network 'development'.
Network up to date.
PS C:\Users\Kofola\BlockChain\EthereumHelloWorld> truffle console
truffle(development)> var hw = HelloWorld.at(HelloWorld.address);
undefined
truffle(development)> hw.address
'0xf169c021288e56a0b9739fd959fe305a7f67f500'
truffle(development)> hw.sayHello();
{ tx: '0x694a532cffb398dd316c53c6ac44adde7d8a7c00e305bcd8b39746fb3d20acdc',
receipt:
{ transactionHash: '0x694a532cffb398dd316c53c6ac44adde7d8a7c00e305bcd8b39746fb3d20acdc',
transactionIndex: 0,
blockHash: '0xdfd7a8637904ec0ed282acac34e2da4929f410325f7f37744955ce5b3195cc8b',
blockNumber: 4,
gasUsed: 21934,
cumulativeGasUsed: 21934,
contractAddress: null,
logs: [],
status: 1 },
logs: [] }
truffle(development)> hw
TruffleContract {
constructor:
{ [Function: TruffleContract]
_static_methods:
{ setProvider: [Function: setProvider],
new: [Function: new],
at: [Function: at],
deployed: [Function: deployed],
defaults: [Function: defaults],
hasNetwork: [Function: hasNetwork],
isDeployed: [Function: isDeployed],
detectNetwork: [Function: detectNetwork],
setNetwork: [Function: setNetwork],
resetAddress: [Function: resetAddress],
link: [Function: link],
clone: [Function: clone],
addProp: [Function: addProp],
toJSON: [Function: toJSON] },
_properties:
{ contract_name: [Object],
contractName: [Object],
abi: [Object],
network: [Function: network],
networks: [Function: networks],
address: [Object],
links: [Function: links],
events: [Function: events],
binary: [Function: binary],
deployedBinary: [Function: deployedBinary],
unlinked_binary: [Object],
bytecode: [Object],
deployedBytecode: [Object],
sourceMap: [Object],
deployedSourceMap: [Object],
source: [Object],
sourcePath: [Object],
ast: [Object],
compiler: [Object],
schema_version: [Function: schema_version],
schemaVersion: [Function: schemaVersion],
updated_at: [Function: updated_at],
updatedAt: [Function: updatedAt] },
_property_values: {},
_json:
{ contractName: 'HelloWorld',
abi: [Array],
bytecode: '0x6060604052341561000f57600080fd5b6101578061001e6000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ef5fb05b14610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600b81526020017f48656c6c6f203230313821000000000000000000000000000000000000000000815250905090565b6020604051908101604052806000815250905600a165627a7a723058201d959a32cbfc1f3e235a39bee940f8e7653bd7d2a041268570ed5b2453d1a9430029',
deployedBytecode: '0x606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ef5fb05b14610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600b81526020017f48656c6c6f203230313821000000000000000000000000000000000000000000815250905090565b6020604051908101604052806000815250905600a165627a7a723058201d959a32cbfc1f3e235a39bee940f8e7653bd7d2a041268570ed5b2453d1a9430029',
sourceMap: '28:114:0:-;;;;;;;;;;;;;;;;;',
deployedSourceMap: '28:114:0:-;;;;;;;;;;;;;;;;;;;;;;;;62:75;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;23:1:-1;8:100;33:3;30:1;27:2;8:100;;;99:1;94:3;90;84:5;80:1;75:3;71;64:6;52:2;49:1;45:3;40:15;;8:100;;;12:14;3:109;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62:75:0;90:6;;:::i;:::-;108:21;;;;;;;;;;;;;;;;;;;;62:75;:::o;28:114::-;;;;;;;;;;;;;;;:::o',
source: 'pragma solidity ^0.4.17;\r\n\r\ncontract HelloWorld{ \r\n \r\n function sayHello() returns(string){\r\n return("Hello 2018!");\r\n
}\r\n\r\n}',
sourcePath: 'C:\\Users\\Kofola\\BlockChain\\EthereumHelloWorld\\contracts\\HelloWorld.sol',
ast: [Object],
compiler: [Object],
networks: [Object],
schemaVersion: '1.0.1',
updatedAt: '2017-12-31T19:58:12.425Z' },
setProvider: [Function: bound setProvider],
new: [Function: bound new],
at: [Function: bound at],
deployed: [Function: bound deployed],
defaults: [Function: bound defaults],
hasNetwork: [Function: bound hasNetwork],
isDeployed: [Function: bound isDeployed],
detectNetwork: [Function: bound detectNetwork],
setNetwork: [Function: bound setNetwork],
resetAddress: [Function: bound resetAddress],
link: [Function: bound link],
clone: [Function: bound clone],
addProp: [Function: bound addProp],
toJSON: [Function: bound toJSON],
web3:
Web3 {
_requestManager: [Object],
currentProvider: [Object],
eth: [Object],
db: [Object],
shh: [Object],
net: [Object],
personal: [Object],
bzz: [Object],
settings: [Object],
version: [Object],
providers: [Object],
_extend: [Object] },
class_defaults:
{ from: '0x848375e1f2447bee3257b9afcac99af09d83f9f0',
gas: 6721975,
gasPrice: 100000000000 },
currentProvider:
HttpProvider {
host: 'http://localhost:8545',
timeout: 0,
user: undefined,
password: undefined,
send: [Function],
sendAsync: [Function],
_alreadyWrapped: true },
network_id: '1001' },
abi:
[ { constant: false,
inputs: [],
name: 'sayHello',
outputs: [Array],
payable: false,
stateMutability: 'nonpayable',
type: 'function' } ],
contract:
Contract {
_eth:
Eth {
_requestManager: [Object],
getBalance: [Object],
getStorageAt: [Object],
getCode: [Object],
getBlock: [Object],
getUncle: [Object],
getCompilers: [Object],
getBlockTransactionCount: [Object],
getBlockUncleCount: [Object],
getTransaction: [Object],
getTransactionFromBlock: [Object],
getTransactionReceipt: [Object],
getTransactionCount: [Object],
call: [Object],
estimateGas: [Object],
sendRawTransaction: [Object],
signTransaction: [Object],
sendTransaction: [Object],
sign: [Object],
compile: [Object],
submitWork: [Object],
getWork: [Object],
coinbase: [Getter],
getCoinbase: [Object],
mining: [Getter],
getMining: [Object],
hashrate: [Getter],
getHashrate: [Object],
syncing: [Getter],
getSyncing: [Object],
gasPrice: [Getter],
getGasPrice: [Object],
accounts: [Getter],
getAccounts: [Object],
blockNumber: [Getter],
getBlockNumber: [Object],
protocolVersion: [Getter],
getProtocolVersion: [Object],
iban: [Object],
sendIBANTransaction: [Function: bound transfer] },
transactionHash: null,
address: '0xf169c021288e56a0b9739fd959fe305a7f67f500',
abi: [ [Object] ],
sayHello:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
'': [Circular] },
allEvents: [Function: bound ] },
sayHello:
{ [Function]
call: [Function],
sendTransaction: [Function],
request: [Function: bound ],
estimateGas: [Function] },
sendTransaction: [Function],
send: [Function],
allEvents: [Function: bound ],
address: '0xf169c021288e56a0b9739fd959fe305a7f67f500',
transactionHash: null }
truffle(development)>
(To exit, press ^C again or type .exit)
truffle(development)> hw.sayHello.call()
'Hello 2018!'
truffle(development)>
솔루션 : 그해야 할 수도 있습니다 같은 문제 READ COMMENTS 받아 들여지는 대답은 다음과 같습니다. 정보.
을 실행하는 명령으로, 코드를 사용 :https://github.com/TomasBisciak/EthereumHelloWorldExample
트뤼플의 'compile'및 'migrate'명령의 출력을 추가 할 수 있습니까? 또한, 어떤 OS를 실행하고 있습니까? 일반적으로 1_initial_migrations.js가 아닌 2_deploy_contracts.js에 배포를 넣으려고하지만 여기에 문제가 있다고 생각하지 않습니다. –
@Adam Kipnis Im Win10 Home 64bit에서 실행 중입니다. 이 프로젝트는 초기화/트뤼플 초기화 명령으로 생성되었습니다. 경고 출력도 관련이 없습니다. 이러한 오류는 편집 된 가시성을 나타냅니다. 내 질문의 코드는 경고없이 여전히 동일한 오류가 발생했습니다. –