wiki icon indicating copy to clipboard operation
wiki copied to clipboard

"value must be string" error when deploying Smart Contract

Open jianhuaixie opened this issue 6 years ago • 3 comments

run example return the error like this: {"result":{"result":"value must be string","execute_err":"Deploy: value must be string","estimate_gas":"21873"}}

jianhuaixie avatar May 10 '18 07:05 jianhuaixie

Hello @jianhuaixie How do you deploy your smart contract? Do you have a screenshot of you operations? That would be very helpful for us to find the problem

ChengOrangeJu avatar May 10 '18 12:05 ChengOrangeJu

I have reproduce this error when deploying contract with web-wellet, the contract source code is using smart_contract.md#blockchain.

Now we take this smart_contract as an example.

The reason for this error is that I leave the arguments for init empty when deploying it. Then the init function will use default value which is undefined as it's arguments. And when assigning value of undefined to bound properties of smart-contract, a error will be throw out: "value must be string" !

That means for bound properties defined by LocalContractStorage.defineProperty(obj, fieldName, descriptor);, you can not assign it a value of undefined such as: this.fieldName = undefined!

'use strict';

var SampleContract = function () {
    LocalContractStorage.defineProperties(this, {
        name: null,
        count: null
    });
    LocalContractStorage.defineMapProperty(this, "allocation");
};

SampleContract.prototype = {
    init: function (name, count, allocation) {
        this.name = name;
        this.count = count;
        allocation.forEach(function (item) {
            this.allocation.put(item.name, item.count);
        }, this);
        // console.log('init: this.name = ' + this.name);
        // console.log('init: this.count = ' + this.count);
        console.log('init: Blockchain.block.coinbase = ' + Blockchain.block.coinbase);
        console.log('init: Blockchain.block.hash = ' + Blockchain.block.hash);
        console.log('init: Blockchain.block.height = ' + Blockchain.block.height);
        console.log('init: Blockchain.transaction.from = ' + Blockchain.transaction.from);
        console.log('init: Blockchain.transaction.to = ' + Blockchain.transaction.to);
        console.log('init: Blockchain.transaction.value = ' + Blockchain.transaction.value);
        console.log('init: Blockchain.transaction.nonce = ' + Blockchain.transaction.nonce);
        console.log('init: Blockchain.transaction.hash = ' + Blockchain.transaction.hash);
    },
    dump: function () {
        console.log('dump: this.name = ' + this.name);
        console.log('dump: this.count = ' + this.count);
    },
    $dump: function () {
        return this.dump();
    },
    dump_1: function () {
        return this.dump();
    },
    verify: function (expectedName, expectedCount, expectedAllocation) {
        if (!Object.is(this.name, expectedName)) {
            throw new Error("name is not the same, expecting " + expectedName + ", actual is " + this.name + ".");
        }
        if (!Object.is(this.count, expectedCount)) {
            throw new Error("count is not the same, expecting " + expectedCount + ", actual is " + this.count + ".");
        }

        expectedAllocation.forEach(function (expectedItem) {
            var count = this.allocation.get(expectedItem.name);
            if (!Object.is(count, expectedItem.count)) {
                throw new Error("count of " + expectedItem.name + " is not the same, expecting " + expectedItem.count + ", actual is " + count + ".");
            }
        }, this);
    }
};

module.exports = SampleContract;

yupnano avatar May 17 '18 08:05 yupnano

你好,此版本为星云旧版wiki,欢迎将您的问题提交星云新版wiki,以便于及时与星云开发人员及其他社区开发者进行交流。同时,参与wiki的编辑维护工作还会有奖励哦。新版wiki链接:https://wiki.nebulas.io/en/latest/ (英文);https://wiki.nebulas.io/zh_CN/latest/ (中文) Hello, this version is the nebulas old wiki (later stop maintenance), welcome to submit your question to the new nebulas wiki, in order to get timely answers. At the same time, there will be rewards for editing and maintaining the wiki. New wiki link: https://wiki.nebulas.io/en/latest/ (English); https://wiki.nebulas.io/zh_CN/latest/ (Chinese)

weiht12 avatar Dec 05 '18 07:12 weiht12