Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开放网络的账号如何获取余额 #40

Open
ygzhu1987 opened this issue Mar 26, 2022 · 12 comments
Open

开放网络的账号如何获取余额 #40

ygzhu1987 opened this issue Mar 26, 2022 · 12 comments

Comments

@ygzhu1987
Copy link

开放网络创建的合约账号,充值后调用接口余额依然为0导致SDK创建合约失败Error TX_VERIFICATION_ERROR while PostTx

@godeamon
Copy link
Collaborator

你好,请问是开放网络还是测试网络呢?另外可以把代码发出来看下吗?

@ygzhu1987
Copy link
Author

ygzhu1987 commented Mar 26, 2022

account.setContractAccount("XC2554587461037348@xuper");
BigInteger result = client.getBalance("XC2554587461037348@xuper");
.......
Transaction t = client.deployEVMContract(account, bin.getBytes(), abi.getBytes(), contractName, args);

是开放网络,试了在测试网络充值后result也是0

@godeamon
Copy link
Collaborator

你好,你可以从开放网络把账户的私钥下载下来,然后使用这个私钥和合约账号进行部署合约,另外查询余额使用公私钥的对应地址试一下。在上面代码中,account 应该是你从开放网络下载的私钥加载出来的 account。可以参考:https://xuper.baidu.com/n/xuperdoc/advanced_usage/open_network.html

@ygzhu1987
Copy link
Author

ygzhu1987 commented Mar 26, 2022

account 是从开放网络下载的私钥加载出来的,试了用公私钥的对应地址查出来是293128,尝试给合约账号赚钱提示:Error TX_VERIFICATION_ERROR while PostTx,代码如下:
client.transfer(account, "XC2554587461037348@xuper", BigInteger.valueOf(290000), "1");

@godeamon
Copy link
Collaborator

不需要给合约账户转账,直接部署或者调用合约即可。你可以在浏览器上部署一个合约然后用sdk调用测试一下,然后可以使用sdk进行部署合约。另外开放网络是不支持转账操作的。

@ygzhu1987
Copy link
Author

ygzhu1987 commented Mar 26, 2022

浏览器上部署的合约sdk是可以调用,用SDK部署合约就会报错:TX_VERIFICATION_ERROR while PostTx
bin和abi是有Counter编译过来的,在自建的节点测试过没问题
Transaction t = client.deployEVMContract(account, bin.getBytes(), abi.getBytes(), contractName, null);

@godeamon
Copy link
Collaborator

使用的配置文件是 sdk.yaml 还是 sdk.testnet.yaml ?

@ygzhu1987
Copy link
Author

sdk.yaml

@superlitian
Copy link

sdk.yaml

发一下完整的调用代码吧,开放网络部署合约使用的是充值在工作台的资源,getBalance入参应该是 account.address。

@ygzhu1987
Copy link
Author

endorseServiceHost: "39.156.69.83:37100"
complianceCheck:
isNeedComplianceCheck: true
isNeedComplianceCheckFee: true
complianceCheckEndorseServiceFee: 400
complianceCheckEndorseServiceFeeAddr: aB2hpHnTBDxko3UoP2BpBZRujwhdcAFoT
complianceCheckEndorseServiceAddr: jknGxa6eyum1JrATWvSJKW3thJ9GKHA9n
minNewChainAmount: "1"
crypto: "xchain"

@ygzhu1987
Copy link
Author

Config.setConfigInputStream(new ClassPathResource("sdk.yaml").getInputStream());
client = new XuperClient("39.156.69.83:37100");
accountFromFile = Account.getAccountFromFile("", "*"); //从开发网络下载的秘钥和密码
accountFromFile.setContractAccount("XC2554587461037348@xuper");

//abi和bin由Counter编译而来,在自建节点通过命令行可以部署
String abi = "";
String bin = "";
Transaction t = client.deployEVMContract(accountFromFile, bin.getBytes(), abi.getBytes(), contractName, null);

@superlitian
Copy link

Config.setConfigInputStream(new ClassPathResource("sdk.yaml").getInputStream());

com.baidu.xuper.config.Config.setConfigPath();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants