问题:调用合约方法时报错Error: Returned error: VM Exception while processing transaction

解决:参数传递错误导致require条件修饰符不满足,web3.js是1.7

方法:

部署合约时传的参数alice是小写开头的,且为byte32

console.time('deploy time');
const myContract = await new web3.eth.Contract(JSON.parse(interface));
myContract.deploy({
    data: bytecode,
    arguments: [[web3.utils.asciiToHex('alice'), web3.utils.asciiToHex('bob')]]
})
.send({
    from: accounts[0],
    gas: 1500000,
    gasPrice: '30000000000000'
})
.then(function(newContractInstance){
    console.log('合约部署成功:', newContractInstance.options.address) // instance with the new contract address
});

阅读全文

问题:以太坊合约部署失败,报错:TypeError: param.map is not a function 或者 Error: Invalid number of parameters for "undefined". Got 2 expected 1!

解决:官方文档写的比较特别,所以被误导了。web3使用的是1.7.0

方法:
官方文档:

const myContract = await new web3.eth.Contract(JSON.parse(interface));    
myContract.deploy({
    data: '0x12345...',
    arguments: [123, 'My String']
})
.send({
    from: '0x1234567890123456789012345678901234567891',
    gas: 1500000,
    gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
.on('error', function(error){ ... })
.on('transactionHash', function(transactionHash){ ... })
.on('receipt', function(receipt){
   console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
});

阅读全文

问题:sqlalchemy的outerjoin外表时需要添加条件,使用filter过滤会到where中,而不是在on语句中

解决:使用and_

方法:

offset_num = (page - 1) * pagesize
q = select(
    User.uid, User.username, User.fullname, User.national_id, User.phone,
    User.gender, User.last_login, User.status, User.create_time,
    func.group_concat(UserRole.role_id).label('role_ids')).outerjoin(
    UserRole, and_(User.uid == UserRole.user_uid,
    UserRole.is_delete == obj_get['is_delete'])).filter(
    User.is_delete == obj_get['is_delete']).group_by(
    User.uid).offset(offset_num).limit(pagesize)
r = await db.execute(q)
return r.all()

阅读全文

问题:为什么用token代替cookie,用token的好处是什么?

解决:

1、cookie
cookie生成过程.jpg

缺点:

跨域限制;
请求接口时默认发送,不安全;
服务器session(redis实现)需要存储用户信息,数据量大时有性能压力;

阅读全文