当您有一个单例样式合同并且其中包含一个时,可能会发生此错误constructor(){}
。如果您不使用构造函数,只需将其删除。或者,您可以在部署合约时使用零参数调用它:
near deploy --accountId example-contract.testnet --wasmFile out/singleton.wasm --initFunction new --initArgs '{}'
或使用 dev-deploy,不传递 accountId 来生成新的 dev-account
near dev-deploy --wasmFile out/singleton.wasm --initFunction new --initArgs '{}'
如果您有一个带有一些参数的构造函数,则在部署它时也需要传递参数
near deploy --accountId example-contract.testnet --wasmFile out/singleton.wasm --initFunction new --initArgs '{"name":"someName"}'
@nearBindgen
export class Contract {
name: string;
// If the constructor is empty without any argumanets, just remove it, and you don't have to think about init.
// constructor(){}
// When you have some arguments in the constructor, you need to call init after it's deployed.
constructor(name:string){
this.name = name;
}
}
如果合约已经部署,我认为当你首先收到此错误时就是这种情况,你也可以在init
之后调用
near call example-contract.testnet init '{"name":"someName"}' --accountId example-contract.testnet
更多信息可以在NEAR 的文档中找到