Skip to content

Commit 22bd118

Browse files
committed
added contract interaction
1 parent 402b001 commit 22bd118

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

example/sign/lib/solana_sample.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:convert';
22
import 'dart:developer';
33

44
import 'package:flutter/material.dart';
5+
import 'package:walletconnect_flutter_dapp/utils/crypto/contract.dart';
56
import 'package:walletconnect_flutter_dapp/utils/dart_defines.dart';
67
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
78
import 'package:walletconnect_modal_flutter/walletconnect_modal_flutter.dart';
@@ -82,6 +83,52 @@ class _MyHomePageState extends State<SolanaSamplePage> {
8283
log('_onSessionEvent ${args.toString()}');
8384
}
8485

86+
void requestReadContract() {
87+
final deployedContract = DeployedContract(
88+
ContractAbi.fromJson(
89+
jsonEncode(ContractDetails.readContractAbi),
90+
'Tether USD',
91+
),
92+
EthereumAddress.fromHex(ContractDetails.contractAddress),
93+
);
94+
95+
_modalService!.web3App!.requestReadContract(
96+
deployedContract: deployedContract,
97+
functionName: 'balanceOf',
98+
rpcUrl: 'https://eth.drpc.org',
99+
parameters: [
100+
// address to read balance of
101+
EthereumAddress.fromHex('0x......'),
102+
],
103+
);
104+
}
105+
106+
void requestWriteContract() {
107+
final deployedContract = DeployedContract(
108+
ContractAbi.fromJson(
109+
jsonEncode(ContractDetails.readContractAbi),
110+
'Tether USD',
111+
),
112+
EthereumAddress.fromHex(ContractDetails.contractAddress),
113+
);
114+
115+
_modalService!.web3App!.requestWriteContract(
116+
deployedContract: deployedContract,
117+
topic: _modalService!.session!.topic,
118+
chainId: 'eip155:1',
119+
rpcUrl: 'https://eth.drpc.org',
120+
functionName: 'transfer',
121+
transaction: Transaction(
122+
from: EthereumAddress.fromHex(_modalService!.address!),
123+
),
124+
parameters: [
125+
// address to transfer to
126+
EthereumAddress.fromHex('0x....'),
127+
BigInt.from(0.0000000000001),
128+
],
129+
);
130+
}
131+
85132
@override
86133
void dispose() {
87134
_modalService!.web3App!.onSessionConnect.unsubscribe(_onSessionConnect);

0 commit comments

Comments
 (0)