启动remixd
remixd -s ./ --remix-ide http://localhost:8080/
或者remixd -s ./ --remix-ide https://remix.ethereum.org/
一、npm install remix-ide -g
npm install @remix-project/remixd -g
二、remix-ide
1.正常返回
Starting Remix IDE at http://localhost:8080 and sharing D:\remix
2.如果报错了
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'remixd'
Require stack:
- C:\Users\璐从今夜白。\AppData\Roaming\npm\node_modules\remix-ide\bin\remix-ide
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\璐从今夜白。\AppData\Roaming\npm\node_modules\remix-ide\bin\remix-ide:4:14)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\璐从今夜白。\\AppData\\Roaming\\npm\\node_modules\\remix-ide\\bin\\remix-ide'
]
}
解决方式: 在报错路径中 \AppData\Roaming\npm\node_modules\remix-ide\bin\remix-ide下,去删除remixd相关内容
去除之前,如下:
#!/usr/bin/env node
var path = require(‘path’)
var httpServer = require(‘http-server’)
var remixd = require(‘remixd’)
var server = httpServer.createServer({undefined
root: path.join(__dirname, ‘/…/’)
})
var folder = process.argv.length > 2 ? process.argv[2] : process.cwd()
server.listen(8080, ‘127.0.0.1’, function () {})
var router = new remixd.Router(65520, remixd.services.sharedFolder, { remixIdeUrl: ‘http://localhost:8080’ }, (webSocket) => {undefined
remixd.services.sharedFolder.setWebSocket(webSocket)
remixd.services.sharedFolder.setupNotifications(folder)
remixd.services.sharedFolder.sharedFolder(folder, false)
})
router.start()
console.log(’\x1b[33m%s\x1b[0m’, 'Starting Remix IDE at http://localhost:8080 and sharing ’ + folder)
去除之后如下:
#!/usr/bin/env node
var path = require(‘path’)
var httpServer = require(‘http-server’)
var server = httpServer.createServer({undefined
root: path.join(__dirname, ‘/…/’)
})
var folder = process.argv.length > 2 ? process.argv[2] : process.cwd()
server.listen(8080, ‘127.0.0.1’, function () {})
console.log(’\x1b[33m%s\x1b[0m’, 'Starting Remix IDE at http://localhost:8080 and sharing ’ + folder)
3.再次运行remix-ide
启动成功后,输入 localhost:8080不行的话,可以考虑加个路径/index ,即:localhost:8080/index,就可以啦
三、用remix打开本地文件
1.npm install -g @remix-project/remixd
2.启动remixd
remixd -s ./ --remix-ide http://localhost:8080/
或者remixd -s ./ --remix-ide https://remix.ethereum.org/
如果是hardhat项目:remixd -s /your/path/to/hardhat-project -remix-ide http://remix.ethereum.org
3.然后用remix连接
四、remix debug
1.局部变量: 函数中的变量
2.状态变量state value(合约中的变量)
其中386 SWAP1
3.把状态变量stateVar 赋值给 memory y, debug过程,其中386 swap1是交换数据赋值:
4.下面3个地方,地址一致:
5.step detail
每一步详情,尤其要分析gas情况
6.函数内部的后退、前进
7.不进入函数内部的后退、前进
8.上一个断点、下一个断点,跳出当前调用
五、部署
5.1部署时,选择金额,是往合约里面充值,2要小于1
5.2 return this是返回address
5.3 view类型,并且有返回值的,在remix按钮下面可以查看
5.4如果调用事件,console面板会打印log,例如:
pragma solidity ^0.4.24;
contract testEvent {
constructor() public payable {
}
event Deposit(address _from, uint _value);
function deposit() public payable {
emit Deposit(msg.sender, msg.value);
}
}