solidity智能合约implicit conversion异常

简介: solidity智能合约implicit conversion异常

问题场景

在使用^0.5.10版本的solidity时,如果使用this关键字会出现以下问题。


代码:


require(tokenContract.balanceOf(this) >= _numberOfTokens);(issue is here)


错误信息:


TypeError: Invalid type for argument in function call. Invalid

 implicit conversion from contract DappTokenSale to address requested.

   require(tokenContract.balanceOf(this) >= _numberOfTokens);


即提示:


implicit conversion from contract DappTokenSale to address


解决方案

使用address(this)替代this。


require(tokenContract.balanceOf(address(this)) >= _numberOfTokens);(issue is here)


目录
相关文章
|
5月前
|
存储 Swift
在Swift编程语言中,变量(Variable)和常量(Constant)
在Swift编程语言中,变量(Variable)和常量(Constant)
86 1
|
5月前
|
程序员 Swift
在Swift编程语言中,Control Transfer Statements
在Swift编程语言中,Control Transfer Statements
57 2
|
自然语言处理 Python
Python 句法错误:"SyntaxError: invalid character in identifier",原因及解决方法
Python 句法错误:"SyntaxError: invalid character in identifier",原因及解决方法
6229 0
|
5月前
|
Rust 自然语言处理 算法
【Rust 中的错误处理:掌握 Option、Result、expect、unwrap 和 ? 运算符】Error Handling in Rust
【Rust 中的错误处理:掌握 Option、Result、expect、unwrap 和 ? 运算符】Error Handling in Rust
194 0
|
5月前
|
Rust 算法 安全
【Rust中的所有权系统深入解析】A Deep Dive into Rust‘s Ownership System
【Rust中的所有权系统深入解析】A Deep Dive into Rust‘s Ownership System
89 0
|
SQL 数据挖掘 Python
令人不悦的Error-TypeError: Cannot perform ‘ror_‘ with a dtyped [...
令人不悦的Error-TypeError: Cannot perform ‘ror_‘ with a dtyped [...
178 0
令人不悦的Error-TypeError: Cannot perform ‘ror_‘ with a dtyped [...
|
存储 Java 编译器
Solidity的Bytecode和Opcode简介
Solidity的Bytecode和Opcode简介
Solidity的Bytecode和Opcode简介
|
JavaScript
什么是 TypeScript 变量的 declared type
什么是 TypeScript 变量的 declared type
115 0
什么是 TypeScript 变量的 declared type
|
前端开发 编译器 区块链
聊聊Solidity中的constant修饰符
聊聊Solidity中的constant修饰符
226 0