Actions
Launch the current wallet​
await _w3mService.launchConnectedWallet();
Send a request​
await _w3mService.web3App!.request(
topic: _w3mService.session.topic,
chainId: 'eip155:1',
request: SessionRequestParams(
method: 'personal_sign',
params: ['Sign this', '0xdeadbeef'],
),
);
A list of all available methods can be found eth_constants.dart file, which is already exported for you to use directly from web3modal package.
List of approved chains by the connected wallet​
_w3mService.getApprovedChains();
List of approved methods by connected wallet​
_w3mService.getApprovedMethods();
List of approved events by the connected wallet​
_w3mService.getApprovedEvents();
Interact with Smart Contracts​
caution
Smart Contracts interaction features are currently in beta. Please install version 3.1.1-beta02
if you want to try it out.
How to use a read function of a Smart Contract​
Future<void> callReadFunction() async {
// Create DeployedContract object using contract's ABI and address
final deployedContract = DeployedContract(
ContractAbi.fromJson(
jsonEncode([{.....}]), // ABI object
'TokenName',
),
EthereumAddress.fromHex('0xaddress.......'),
);
// Get balance of wallet
return await _w3mService.requestReadContract(
deployedContract: deployedContract,
functionName: 'balanceOf',
rpcUrl: 'https://{rpc-url}.com',
parameters: [
EthereumAddress.fromHex('0xaddress....'),
],
);
// Get token total supply
return await _w3mService.requestReadContract(
deployedContract: deployedContract,
functionName: 'totalSupply',
rpcUrl: 'https://{rpc-url}.com',
);
}
How to use a write frunction of a Smart Contract​
Future<void> callWriteFunction() async {
// Create DeployedContract object using contract's ABI and address
final deployedContract = DeployedContract(
ContractAbi.fromJson(
jsonEncode([{.....}]), // ABI object
'TokenName',
),
EthereumAddress.fromHex('0xaddress.......'),
);
// Transfer 0.01 amount of Token using Smart Contract's transfer function
return await _w3mService.requestWriteContract(
topic: _w3mService.session.topic,
chainId: 'eip155:1',
rpcUrl: 'https://{rpc-url}.com',
deployedContract: contract,
functionName: 'transfer',
transaction: Transaction(
from: EthereumAddress.fromHex('0xaddressFrom....'),
to: EthereumAddress.fromHex('0xaddressTo....')
value: EtherAmount.fromInt(EtherUnit.finney, 10), // == 0.010
),
);
}
For a complete example app check out the example app for Web3Modal
Was this helpful?