简体   繁体   English

尝试在专用网络上进行交易时,帐户余额为零

[英]Account balance zero when trying to make an transaction on private network

EDIT: solved, was caused by declaring this.web3 instead of web3 编辑:解决,是由声明this.web3而不是web3引起的

I'm running a private network with truffle and I'm facing this weird problem where at Metamask and Mist show that I have balance of 100 eth. 我正在运行带有松露的专用网络,并且遇到了这个奇怪的问题,在Metamask和Mist处显示我的平衡为100 eth。 When I try actually to make an transaction it says that the account has ZERO eth. 当我实际尝试进行交易时,它说该帐户具有零eth。 I have a contract that is fairly complex and I'm not sure what is the problem. 我的合同相当复杂,我不确定是什么问题。

I have tried restarting truffle and recompiling and remigrating the contracts a few times and I have reinstalled metamask multiple times. 我尝试几次重新启动松露,重新编译和迁移合同,并且多次重新安装了metamask。 When I tried Mist, it also does this. 当我尝试Mist时,它也会这样做。

I'm fairly new at smart contracts, but I'm trying to create a somewhat big application with it. 我在智能合约方面还很陌生,但是我正在尝试用它创建一个更大的应用程序。 I code the contracts with Solidity and I have tested the contracts on remix without problems and I can manipulate the contracts via truffle just fine. 我使用Solidity对合同进行编码,并且已经对混音中的合同进行了测试,没有任何问题,并且可以通过松露操作合同。 I think it may be because of the front.. I'm programming it with react. 我认为可能是因为前端。我正在用react编程。 This is the specific part of code in js that I call the function. 这是我称为js的代码中的特定部分。 It's just a plain auth mechanism. 这只是一种简单的身份验证机制。 I use truffle-contract and this.database is a Contract. 我使用松露合约,this.database是合约。

authAddress(sotu, password) {
    return new Promise ((resolve, reject) => {
        this.database.deployed().then(instance => {
            return instance.authAddress(sotu, password);
        }).then(res => {
            resolve();
        }).catch(error => {
            reject(error);
        });
    });
}

The solidity counterpart is follows: 坚固性对应如下:

function authAddress(string sotu, string password) public {
    //Check if already logged in
    require(authenticatedAddresses[msg.sender] == address(0));
    Person p = persons[keccak256(sotu)];
    p.login(keccak256(password), msg.sender);
    authenticatedAddresses[msg.sender] = p;
}

I'm still learning these things, but I'm a bit bummed that this problem exists and nobody else seems to have countered this as far as I have tried to search. 我仍在学习这些内容,但是对于这个问题的存在我感到有些沮丧,就我尝试搜索的情况而言,似乎没有其他人对此提出反驳。 Have I missed something completely? 我完全错过了什么吗?

EDIT: 编辑:

Here's tbe web3 provider init: 这是web3提供程序init:

    try {
        if(web3 != null) {
            this.web3 = new Web3(web3.currentProvider);
        }
    } catch (error) {
        this.web3 = null;
    }

I try to make the site only available if you have metamask or such alike. 我尝试仅当您具有metamask或类似标记时才使该站点可用。 I'd like to to wrap the web3 to a class, but if that screws things uo let me know. 我想将web3包装到一个类中,但是如果这使uo搞砸了,请告诉我。

My databasehandler init 我的数据库处理程序初始化

initDatabaseHandler() {
    return new Promise((resolve, reject) => {
        this.databaseHandler = new DatabaseHandler();
        this.databaseHandler.loadContract(this.state.coinbase, this.web3.currentProvider)
        .then(() => {
            this.databaseHandler.getAccountInfo()
            .then(info => {
                this.setState({userinfo: info}, resolve());
            }).catch(err => {
                console.log(err);
            });
        })
        .catch(err => reject(err));

    });
}

And the abstracted contract loader: 和抽象的合同加载器:

loadContract(coinbase, provider) {
    return new Promise((resolve, reject) => {
        this.database = new Contract(Database);
        this.database.setProvider(provider);
        this.database.web3.eth.defaultAccount = coinbase;

        this.person = new Contract(Person);
        this.person.setProvider(provider);
        this.person.web3.eth.defaultAccount = coinbase;

        console.log(this.database.web3.eth.defaultAccount);
        resolve();

    });
}

解决,是由于声明了this.web3而不是web3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VMware专用内部网络 - VMware private internal network Xcode 网络扩展帐户 - Xcode Network Extensions Account 主机在专用网络上扫描 - Host scanning on a private network 连接到专用网络上的服务器 - Connect to a server on a private network “KeyVaultAuthenticationFailure”当存储帐户尝试使用专用端点访问 Key Vault 中的客户托管密钥时(使用 Terraform) - "KeyVaultAuthenticationFailure" when Storage Account attempts to Access Customer Managed Key in Key Vault with Private Endpoint (Using Terraform) 尝试将iPod touch连接到我的服务器时网络超时 - Network time out when trying to connect ipod touch to my server 网络中专用IP的子域 - Subdomains to Private IP's in a network Terraform 使用专用端点创建 function 应用程序和存储帐户时出现 403 错误 - Terraform 403 error when creating function app and storage account with private endpoint 尝试使流量流向多个网络接口时出现游荡问题 - Vagrant issue when trying to get traffic flowing to multiple network interfaces 当服务器位于专用网络上时,使用TCP通过套接字在两个设备之间发送字符串 - Sending a string between two devices through a socket using TCP when server is on a private network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM