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

How to connect the smart contract with mobile app? #6

Open
mzxyz opened this issue Sep 4, 2019 · 1 comment
Open

How to connect the smart contract with mobile app? #6

mzxyz opened this issue Sep 4, 2019 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@mzxyz
Copy link
Contributor

mzxyz commented Sep 4, 2019

No description provided.

@mzxyz mzxyz added documentation Improvements or additions to documentation question Further information is requested labels Sep 4, 2019
@mzxyz mzxyz self-assigned this Sep 4, 2019
@mzxyz
Copy link
Contributor Author

mzxyz commented Sep 4, 2019

1. Build and deploy the contract

You can follow this doc to build and deploy the contract: spin2win.

2. Contract address and ABI file

After you build and deploy the contract you will get two items to be used in the next step:

For Contract ABI of spin2win:

"messages": [{
    "name": "spin",
    "selector": 2121348255,
    "mutates": false,
    "args": [{
      "name": "player",
      "type": "AccountId"
    }],
    "return_type": null
  }]

You will see there is only one method in the contract, and the method name is spin, and only one parameter for spin, the type is AccountId.

3. Calling contract

Construct a ContractABI instance:

You can use this instance to call any messages in the contract ABI file with the correct args. The function will return a payload (hex value), this signature includes all the information of the message.

Create transaction:

Creating api and set signer.

Calling api.tx.contract.call to get tx object:

  const tx =  api.tx.contract.call(
    contractAddress,
    endowment, // deposit amount, can be 0: BigNumber
    200000,    // gas fee
    payload    // the payload when calling specific message
  );

The last step: sign and send the tx. You can get the transaction status and all the event details inside the code and also check them on CENNZnet UI with block hash.

4. Common issues

  • The signer should have enough funds to sign a transaction. You can get tokens through faucet.
  • The network(Localhost or Rimu) of deploying contract and calling contract should be the same one.
  • For spin2win contract, should make sure the contract has enough funds to allocate assets. You can also top up the contract, using contract address, through faucet.

mzxyz pushed a commit that referenced this issue Sep 4, 2019
Add #6 to README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant