我正在尝试使用统一性编程来创建令牌,但是在重新混合浏览器IDE上进行编译时,始终出现此未声明的标识符错误。我是新手,如何解决这个问题?
我在这里附加了我的代码:
pragma solidity >=0.4.16 < 0.6.0;
/*declare an interfaced named tokenReceipent so that any contract that implements receiveApproval function counts as a tokenReceipent*/
interface tokenRecipient
{
function receiveApproval(address _from, uint256 _value, address _token, bytes calldata _extraData) external;
}
contract TokenERC20 //create a contract ERC20 and declare public variables of the token
{
string public name;
string public symbol;
uint8 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256)public balanceOf; // create mapping with all balances
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value); //create an event on blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed from,uint256 value); //create an event that notifies clients about the amount burn
constructor(uint256 initialSupply, string memory tokenName, string memory tokenSymbol) // create a construct that initialized tokens to the creator of the contract
public
{
totalSupply = initialSupply*10** uint256(decimals); //update total supply with des 1 1 out
balanceOf[msg.sender]=totalSupply;//give creator all initial tokens
name=tokenName; //set the name and symbol for display purposes
symbol=tokenSymbol;
}
//create an internal function and can only be called by this smartContract
function _transfer(address _from, address _to, uint _value) internal
{
//prevent transfer to 0x0 address
//check that the balance of the sender has enough
//add thesame to the recepient
//insert assert to use static analysis to find bugs in your code,they should never fail
require(_to!=address(0x0));
//subtract from the sender
require(balanceOf[_from]>= _value);
//add thesame to the receipent
require(balanceOf[_to] + _value>= balanceOf[_to]);
uint previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_from] += _value;
emit Transfer(_from , _to, _value);
//assert are used to find static analysis in your code,they should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
//create to transfer function
function transfer(address _to, uint256 _value)
public returns(bool success)
{
_transfer(msg.sender, _to, _value);
return true;
}
//create a from transfer function to transfer tokens from other address
function transferFrom(address _from, address _to, uint256 _value)
public returns(bool success)
{
require(_value <= allowance[_from][msg.sender]);
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
//create allowances for other address
//allows spender not spend a certain allowance on your behalf
function approveAndCall(address _spender, uint256 _value, bytes memory _extraData)
public returns(bool success)
{
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
}
function burn(uint256 _value)
public returns (bool success)
{
require(balanceOf[msg.sender]>= _value);
balanceOf[msg.sender] -= _value; //subtract from the sender
totalSupply -= _value; //update the total supply of tokens
emit Burn(msg.sender, _value);
return true;
}
// function that destroys token from other(users/subscribers) accounts
function burnFrom(address _from, uint256 _value)
public returns(bool success)
{
require(balanceOf[_from] >= _value);
require(_value <= allowance[_from][msg.sender]);
balanceOf[_from] -= _value;
allowance[_from][msg.sender] -= _value;
totalSupply -= _value;
emit Burn(_from, _value);
return true;
}
}
答案 0 :(得分:0)
由于以下错误,代码无法编译:
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
tf.__version__
import numpy as np
import os
from tensorflow.keras import layers
import librosa
import librosa.display
import matplotlib.pyplot as plt
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
sr = 44100/2
sample_path = os.getcwd()
def make_generator_model():
model = tf.keras.Sequential()
model.add(layers.Dense(2*7*19*128, use_bias=False, dtype='float32', input_shape=(50,)))
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Reshape((2 ,7, 19, 128)))
assert model.output_shape == (None,2, 7, 19, 128) # Note: None is the batch size
model.add(layers.Conv3DTranspose(128, (1, 6, 1), strides=(1, 6, 1), padding='same', use_bias=False))
assert model.output_shape == (None, 2, 42, 19, 128)
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv3DTranspose(128, (1, 3, 19), strides=(1, 3, 19), padding='same', use_bias=False))
assert model.output_shape == (None, 2, 126, 361, 128)
model.add(layers.BatchNormalization())
model.add(layers.LeakyReLU())
model.add(layers.Conv3DTranspose(1, (1, 2, 1), strides=(1, 2, 1), padding='same', use_bias=False, activation='tanh'))
assert model.output_shape == (None, 2, 252, 361, 1)
return model
generator = make_generator_model()
noise = tf.random.normal([1, 50])
generated_audio = generator(noise, training=False)
D = []
for x in range(len(generated_audio[0][0])):
this_line = []
for y in range(len(generated_audio[0][0][x])):
this_line.append(np.complex(generated_audio[0][0][x][y],generated_audio[0][1][x][y]))
D.append(this_line)
D = np.asarray(D)
librosa.display.specshow(librosa.amplitude_to_db(np.abs(D), ref=np.max),
sr=sr, x_axis='time', y_axis='cqt_note')
plt.axis('off')
plt.savefig(sample_path + '\\image_at_epoch_fuzz.png')
plt.show()
print(D.shape)
您的代码未声明browser/Token.sol:73:17: DeclarationError: Undeclared identifier.
if (approve(_spender, _value)) {
^-----^
函数,因此出现错误。
如果您不是自己编写代码,建议您检查approve
函数的原始代码。
approve
要了解令牌,我建议您阅读有关令牌的OpenZeppelin文档: https://docs.openzeppelin.org/v2.3.0/tokens
您可以将使用OpenZeppelin和Remix的简单令牌部署到测试网
function approveAndCall(address _spender, uint256 _value, bytes memory _extraData)
public returns(bool success)
{
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
}
您也可以在以下位置提问: