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

Smart Contracts (read and write) Interaction #256

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

quetool
Copy link
Collaborator

@quetool quetool commented Feb 1, 2024

Description

Based on @bobwith2bees implementation we added support for a better interaction with smart contracts.

Resolves #255

How Has This Been Tested?

Due Dilligence

  • Breaking change
  • Requires a documentation update
Demo using WalletConnect's Flutter dApp
and WalletConnect's Flutter Wallet
(both included in this repository)
Demo using WalletConnect's Flutter dApp
and Zerion wallet

Example

  • Example on how to call transfer function from a Smart Contract to send 0.010 value of it's token.
final deployedContract = DeployedContract(
  ContractAbi.fromJson(
    jsonEncode({contract-abi}),
    'SmartContract_Name',
  ),
  EthereumAddress.fromHex('smart_contract_address'),
);

return web3App.requestWriteContract(
  topic: topic,
  chainId: 'eip155:11155111',
  rpcUrl: 'https://ethereum-sepolia.publicnode.com',
  deployedContract: deployedContract,
  functionName: 'transfer',
  transaction: Transaction(
    from: EthereumAddress.fromHex(address),
    to: EthereumAddress.fromHex('0x59e2f66C0E96803206B6486cDb39029abAE834c0'),
    value: EtherAmount.fromInt(EtherUnit.finney, 10), // == 0.010
  ),
);
  • Example on how to call balanceOf function of a Smart Contract to check wallet balance of it's token.
final deployedContract = DeployedContract(
  ContractAbi.fromJson(
    jsonEncode({contract-abi}),
    'SmartContract_Name',
  ),
  EthereumAddress.fromHex('smart_contract_address'),
);

return web3App.requestReadContract(
  deployedContract: deployedContract,
  functionName: 'balanceOf',
  rpcUrl: 'https://ethereum-sepolia.publicnode.com',
  parameters: [
    EthereumAddress.fromHex('0xaddress'),
  ],
);

@quetool quetool added the enhancement New feature or request label Feb 1, 2024
@quetool quetool self-assigned this Feb 1, 2024
@quetool quetool merged commit c703f7f into master Feb 1, 2024
1 check passed
@quetool quetool deleted the feature/smart_contracts_interaction branch April 2, 2024 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smart Contracts (read and write) Interaction
1 participant