Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合约部署构造函数传参问题和创建问题 #94

Open
lmhaoye opened this issue Jan 31, 2018 · 1 comment
Open

合约部署构造函数传参问题和创建问题 #94

lmhaoye opened this issue Jan 31, 2018 · 1 comment

Comments

@lmhaoye
Copy link

lmhaoye commented Jan 31, 2018

请问合约这块,怎么部署有构造参数的只能合约,
我测试过web3的 contract.new 或者合约实例(instance.method)
都会报

Account unkonw.

而且在BCOS中 执行合约和部署合约只能走 sendRawTransaction 方法构建sign后的交易数据,

我尝试改造web3sync的 rawDeploy 方法,
增加

var encodeConstructorParams = function (abi, params) {
    return abi.filter(function (json) {
        return json.type === 'constructor' && json.inputs.length === params.length;
    }).map(function (json) {
        return json.inputs.map(function (input) {
            return input.type;
        });
    }).map(function (types) {
        return coder.codeParams(types, params);
    })[0] || '';
};

用来对构造函数的参数进行encode后的 数据,添加到了postdata中的data,但发现合约是能正常部署成功,但是参数还是未能顺利传递进去,

求指导,构造函数这块的参数怎么搞,或者怎么能够正常使用web3 的 contract.new 或者contract.method?

@toxotguo
Copy link
Contributor

@lmhaoye
web3sync.js已经做了优化可以支持部署智能合约时的构造函数参数传入。
请参考 https://github.com/FISCO-BCOS/FISCO-BCOS/blob/master/web3lib/web3sync.js中对rawDeploy实现。
function rawDeploy(account, privateKey,filename,types,params,debug)
其中type是构造函数的参数类型,params是构造函数的入参

Honglei-Cong pushed a commit to Honglei-Cong/bcos that referenced this issue Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants