获取某个账号(钱包地址)的最新余额 以下代码就是获取制定账户余额的方法,获取到的余额是16进制的wei,在获取余额成功后我已经做了转换,params中两个参数,第1个是你要查询的账户(钱包地址),第2个是固定参数,表示最新余额。获取余额ethereum。request({method:ethgetBalance,params:〔0xBcFf5a3c1970D795777d7471F2792832BAF5679d,latest〕})。then((result){console。log(获取余额successresult)letformartEtherethers。utils。formatEther(result);16进制的weiconsole。log(formartEther)})。catch((error){console。log(获取余额errorerror。code)}); 或者:连接账号functionconnect(){console。log(Callingconnect())ethereum。request({method:ethrequestAccounts})。then(handleAccountsChanged)。catch((err){if(err。code4001){EIP1193userRejectedRequesterrorIfthishappens,theuserrejectedtheconnectionrequest。账号拒绝登录metamaskconsole。log(PleaseconnecttoMetaMask。);(status)。html(YourefusedtoconnectMetamask)}else{console。error(err);}});}获取交易回执 发出支付请求ethereum。request({method:ethsendTransaction,params:〔{from:fromAddress,to:toAddress,value:value,}〕})。then((result){console。log(result)0xec9026d3a9d4cd4d44ac7cd49186a05c8a2db4d697a05207d8e804d2a245455aif(result!nullresult!undefined){console。log(开始计时)letparamsStr〔〕;对应查询时的参数params,列表paramsStr〔0〕result;需要等待十秒才能收到回执单信息返回回执代码串和回执单不是同时的所以有时候能直接通过回执代码串获取到回执单有时候获取不到可能跟网速有关系所以在获取到回执代码串之后延时十秒再获取回执单即可setTimeout(function(){getReceipt(paramsStr)10秒后执行下面的函数,获取交易回执},10000);}})。catch((error){});获取回执单的方法functiongetReceipt(paramsStr){ethereum。request({method:ethgetTransactionReceipt,params:paramsStr})。then((result){console。log(result)})。catch((error){console。log(errorerror。message)Iftherequestfails,thePromisewillrejectwithanerror。});} 发出支付请求之10秒后,通过返回值paramsStr,即TransactionHash从以太坊交易中读取交易回执信息。 编辑切换为居中 添加图片注释,不超过140字(可选) 回执: 编辑切换为居中 添加图片注释,不超过140字(可选)实际操作 在交易提交返回到TransactionHash时,说明交易成功,可以在这个时候将TransactionHash及其他交易信息,一并提交至数据库。至于获取订单回执,随时可以通过钱包地址及TransactionHash获取。