{"author":{"address":null,"user":"https://learnblockchain.cn/people/22222"},"content":{"body":"今天调试手工采用node 调用web3.js\r\n# 1.创建合约失败的 过程:执行后contract address是null的代码:\r\n\r\n## 1.1 下面的code 取值从remix里面拷贝byte code\r\n```js\r\ncode = '0x608060405234801561001057600080fd5b5061025d806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80630acc083e1461004657806385d8284c14610076578063bcb4ab0e14610095575b600080fd5b610060600480360381019061005b9190610144565b6100b4565b60405161006d9190610180565b60405180910390f35b61007e6100ca565b60405161008c92919061019b565b60405180910390f35b61009d6100e5565b6040516100ab92919061019b565b60405180910390f35b60006001826100c391906101f3565b9050919050565b60008060016000546100dc91906101f3565b5a915091509091565b60008060016000546100f791906101f3565b6000819055506000545a915091509091565b600080fd5b6000819050919050565b6101218161010e565b811461012c57600080fd5b50565b60008135905061013e81610118565b92915050565b60006020828403121561015a57610159610109565b5b60006101688482850161012f565b91505092915050565b61017a8161010e565b82525050565b60006020820190506101956000830184610171565b92915050565b60006040820190506101b06000830185610171565b6101bd6020830184610171565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006101fe8261010e565b91506102098361010e565b9250828201905080821115610221576102206101c4565b5b9291505056fea26469706673582212204f34bb1b403e445a9b5ec4ca4cbc912cb5614c210931fd57fe93ee7a3b68466264736f6c63430008110033'\r\n```\r\n\r\n## 1.2 使用nodejs 调用web3.js 的方式\r\n```shell\r\nnpm init -y\r\nnpm i web3\r\nnode \r\n```\r\n\r\n## 1.2 使用web3.js 来执行\r\n```js\r\n\r\nurl = 'http://localhost:8545'\r\n{Web3} = require('web3')\r\nweb3 = new Web3(url)\r\n\r\naccounts  = await  web3.eth.getAccounts()\r\nzero ='0x0000000000000000000000000000000000000000'\r\n\r\ntx = {from : accounts[0], to:zero, data: code}\r\nreceipt =  await  web3.eth.sendTransaction(tx)\r\n ```\r\n\r\n\r\n# 2. 创建成功的代码\r\ntx.to 不赋值\r\n```js\r\n\r\nurl = 'http://localhost:8545'\r\n{Web3} = require('web3')\r\nweb3 = new Web3(url)\r\n\r\naccounts  = await  web3.eth.getAccounts()\r\n//zero ='0x0000000000000000000000000000000000000000'\r\n//web3 create transaction, do not set the tx.to zero address, zero address means detroy coin\r\n// undefined tx.to means create transaction\r\ntx = {from : accounts[0], data: code}\r\nreceipt =  await  web3.eth.sendTransaction(tx)\r\n \r\n```","title":"web3.js 手工创建合约 不能设置 to 参数"},"history":null,"timestamp":1726304341,"version":1}