smart contract storage struct 未初始化 直接使用問題

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

2019-09-26 · 1 min · 8 words · Me

web3 deploy smart contract 1.2.1

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.log("web3 version: %o", web3.version) web3.eth.getAccounts().then(o=>{console.log(o)}) cContract.deploy().send() .on('error', (error) => { console.log("error: %o", error) }) .on('transactionHash', (transactionHash) => { console.log("transactionHash: %o", transactionHash) }) .on('receipt', (receipt) => { // receipt will contain deployed contract address console.log("receipt: %o", receipt) console.log("receipt.contractAddress: %o", receipt.contractAddress) }) .on('confirmation', (confirmationNumber, receipt) => { console.log("confirmationNumber: %o", confirmationNumber) console.log("confirmation receipt: %o", receipt) }) .then(function(newContractInstance){ if (typeof newContractInstance.options.address !== 'undefined') { console.log('Contract mined! address: ' + newContractInstance.options.address); }else{ console.log("newContractInstance.address is undefined!") } });

2019-09-26 · 1 min · 141 words · Me

HDWalletProvider web3 smart contract connection need to stop or pool

HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.engine.stop(); } }; const factory1 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1); }, destroy: function(client) { client.engine.stop(); } }; export function ReleaseHDProvider1(client){ Provider1Pool.release(client); console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending) } export function ReleaseHDProvider2(client){ Provider2Pool.release(client); console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending) } const Provider1Pool = genericPool.createPool(factory0, opts); const Provider2Pool = genericPool.createPool(factory1, opts);

2019-09-25 · 1 min · 179 words · Me

solc abigen docker

sol file put in ~/contracts/sol File list ~/contracts/sol/Contracts.sol RUN docker run -v ~/contracts:/sources ethereum/solc:0.4.23 -o /sources --abi --bin /sources/sol/Contract.sol File list ~/contracts/sol/Contracts.sol ~/contracts/Contracts.abi ~/contracts/Contracts.bin 0.4.23 check your contract version. This example is pragma solidity ^0.4.23; sol name need be changeed. This example is Contract.sol Permission denied just use root RUN docker run -v ~/contracts:/sources ethereum/client-go:alltools-v1.9.2 abigen --abi /sources/Contract.abi --pkg contracts --type Contract --out /sources/Contract.go --bin /sources/Contract.bin File list ~/contracts/sol/Contracts.sol ~/contracts/Contracts.abi ~/contracts/Contracts.bin ~/contracts/Contracts.go ...

2019-09-03 · 1 min · 141 words · Me

go-eth

https://medium.com/taipei-ethereum-meetup/%E4%BD%BF%E7%94%A8-go-%E8%88%87%E4%BB%A5%E5%A4%AA%E5%9D%8A%E5%8D%80%E5%A1%8A%E9%8F%88%E4%BA%92%E5%8B%95-%E4%B8%89-7b7b1f40c06a https://github.com/sc0Vu/go-eth

2019-09-02 · 1 min · 2 words · Me