every sec send transaction nonce++ https://medium.com/finnovate-io/how-do-i-sign-transactions-with-web3-f90a853904a2 https://ethereum.stackexchange.com/questions/60611/defining-the-transaction-object-for-offline-transaction-signing-using-web3-js-f https://github.com/ethereum/web3.js/issues/1430 https://programtheblockchain.com/posts/ signTransaction(tx, “0x”+privateKey) “0x” privatekey need becarful. --ws --wsaddr 0.0.0.0 --wsorigins "*" --wsapi "db,admin,debug,miner,eth,net,web3,network,txpool" var fs = require('fs'); var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://192.168.99.100:18545"); var wsprovider = new Web3.providers.WebsocketProvider("ws://192.168.99.100:18546"); //var web3 = new Web3(provider); var web3 = new Web3(wsprovider); console.log("before web set account: %o", web3.eth.defaultAccount); const privateKey = '138cbbfb21686ddc3b5ffeb2cfc83491175af68319977acb81d0ae93392c626c'; const account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey); //web3.eth.accounts.wallet.add(account); //console.log("private key import to account: %o", account.

繼續閱讀

Important!! web3.eth.sendTransaction({ data: bytecode “certjson.bytecode” or “certjson.bytecode.object” MUST Have “0x” at line First Character Use Truffle 1. run https://www.trufflesuite.com/docs/truffle/quickstart 1-1. run command mkdir testtruffle cd testtruffle npm i web3 truffle unbox metacoin truffle test ./test/TestMetaCoin.sol truffle test ./test/metacoin.js truffle compile 2. modify truffle-config.js Here use your private poa chain networkinfo. from address must be can used. genesis file can put this address. module.exports = { // Uncommenting the defaults below // provides for an easier quick-start with Ganache.

繼續閱讀

https://github.com/knownsec/Ethereum-Smart-Contracts-Security-CheckList/blob/master/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E5%AE%A1%E8%AE%A1CheckList.md#11-%E6%9C%AA%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%82%A8%E5%AD%98%E6%8C%87%E9%92%88 https://www.chaindd.com/3102377.html https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089 https://medium.com/loom-network/ethereum-solidity-memory-vs-storage-how-to-initialize-an-array-inside-a-struct-184baf6aa2eb Use delete or new

繼續閱讀

Use https://remix.ethereum.org Get Contract json and data. In remix website, Compile finish. See Compliation Details. 1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space 2. Compliation Details -> WEB3DEPLOY -> get data 3. cContract.options.from need put correct. var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://ganache:8545"); var web3 = new Web3(provider); //abi var cContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]) //bytecode cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029' cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx' cContract.options.gas = '4700000' console.

繼續閱讀

uint256 => 2^256 byte32 => 2^8^32 (byte=2^8) or 32個byte 放32字元(ascii) 0x => HEX 16進位 0x64 => 6 * (16^1) + 4 * (16^0) = 100 0x0164 => 1 * (16^2) + 6 * (16^1) + 4 * (16^0) = 365 0x HEX 16進位 最小0 最大F 回到最上面byte32 轉成 0x HEX 為了避免太長,2^8 = 256 => 16^2 => 16位元顯示要兩位 0~256 => 00~FF || FF => 15 * (16^1) + 15 * (16^0) 所以 0x0164,通常都是兩位處理 0x 01 64

繼續閱讀

https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e 上面範例中,play(100)被呼叫後,從transcation data內得知 0x6587f6ec0000000000000000000000000000000000000000000000000000000000000064 然後先取得play()這部份的data bytes4(keccak256(‘play(uint)')) 然後得知 0000000000000000000000000000000000000000000000000000000000000064 就是 uint部份,得到的這個值是經過hex才顯示的 byte32:00 為1個byte(16 bits),共32個 64=> 6 * (16^1) + 4 * (16^0) = 100 uint256 => 2^256 => 8^32 => byte32

繼續閱讀

作者的圖片

Sue boy

Sueboy Can support You

CIO

Taiwan