Skip to content

Instantly share code, notes, and snippets.

@yutakikuchi
Last active June 6, 2022 18:28
Show Gist options
  • Save yutakikuchi/407e1e5fc4522c57d63fe16a46c633bf to your computer and use it in GitHub Desktop.
Save yutakikuchi/407e1e5fc4522c57d63fe16a46c633bf to your computer and use it in GitHub Desktop.
send_mint_transaction_with_walletconnect(using flutter)
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter/gestures.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:walletconnect_dart/walletconnect_dart.dart';
import 'package:web3dart/web3dart.dart';
import 'package:http/http.dart';
// please add widget logic
Future<void> _build_wallet_connect(BuildContext context, String tokenUrl) async {
late String account;
late SessionStatus session;
final String your_contract_address = 'xxxxx';
final String your_infra_url = 'https://yyyyy';
// Create a connector
final connector = WalletConnect(
bridge: 'https://bridge.walletconnect.org',
clientMeta: PeerMeta(
name: 'WalletConnect',
description: 'WalletConnect Developer App',
url: 'https://walletconnect.org',
icons: [
'https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media'
],
),
);
if (!connector.connected) {
session = await connector.createSession(
// this is polygon mumbai chainid
chainId: 80001,
onDisplayUri: (uri) async {
setState(() {
_url = uri;
});
}
);
}
setState(() {
account = session.accounts[0];
});
final contractAddr = EthereumAddress.fromHex(your_contract_address);
final client = Web3Client(your_infra_url, Client());
EthereumWalletConnectProvider provider = EthereumWalletConnectProvider(connector);
final userAddress = EthereumAddress.fromHex(account);
final credentials = WalletConnectEthereumCredentials(provider: provider);
String abiCode = await rootBundle.loadString('json/abi.json');
final contract = DeployedContract(ContractAbi.fromJson(abiCode, 'Your Contract Name'), contractAddr);
final mint_function = contract.function('xxxxxx');
await client.sendTransaction(
credentials,
Transaction.callContract(
contract: contract,
function: mint_function,
parameters: [userAddress, tokenUrl],
from: userAddress,
nonce: await client.getTransactionCount(userAddress,atBlock: BlockNum.pending()),
),
);
connector.killSession();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment