Skip to content

Commit 1bb7cf4

Browse files
committed
Up to date dependencies.
1 parent 759c436 commit 1bb7cf4

6 files changed

Lines changed: 90 additions & 73 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.0
2+
3+
* Up to date dependencies.
4+
15
## 1.0.1
26

37
* Adds example project.

analysis_options.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ analyzer:
2222
dead_code: error
2323
duplicate_import: error
2424
file_names: error
25-
implicit_dynamic_function: ignore
26-
implicit_dynamic_parameter: error
27-
implicit_dynamic_list_literal: ignore
28-
implicit_dynamic_map_literal: ignore
29-
implicit_dynamic_method: ignore
30-
implicit_dynamic_type: ignore
31-
implicit_dynamic_variable: ignore
3225
invalid_assignment: error
3326
missing_return: error
3427
prefer_const_constructors: error

lib/erc20.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
library erc20;
22

3-
export 'src/erc20.dart';
3+
import 'package:web3dart/web3dart.dart';
4+
import 'package:wallet/wallet.dart';
5+
6+
part 'src/erc20.dart';

lib/src/erc20.dart

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import 'package:web3dart/web3dart.dart' as web3;
1+
part of '../erc20.dart';
22

3-
final _contractAbi = web3.ContractAbi.fromJson(
4-
'[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]',
5-
'Erc20');
3+
final _contractAbi = ContractAbi.fromJson(
4+
'[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]',
5+
'Erc20',
6+
);
67

78
/// Interface of the ERC20 standard as defined in the EIP.
8-
class ERC20 extends web3.GeneratedContract {
9+
class ERC20 extends GeneratedContract {
910
/// Constructor.
1011
ERC20({
11-
required web3.EthereumAddress address,
12-
required web3.Web3Client client,
12+
required EthereumAddress address,
13+
required Web3Client client,
1314
int? chainId,
14-
}) : super(web3.DeployedContract(_contractAbi, address), client, chainId);
15+
}) : super(DeployedContract(_contractAbi, address), client, chainId);
1516

1617
/// Returns the remaining number of tokens that [spender] will be allowed to spend on behalf of [owner] through [transferFrom]. This is zero by default. This value changes when [approve] or [transferFrom] are called.
1718
///
1819
/// The optional [atBlock] parameter can be used to view historical data. When
1920
/// set, the function will be evaluated in the specified block. By default, the
2021
/// latest on-chain block will be used.
2122
Future<BigInt> allowance(
22-
web3.EthereumAddress owner,
23-
web3.EthereumAddress spender, {
24-
web3.BlockNum? atBlock,
23+
EthereumAddress owner,
24+
EthereumAddress spender, {
25+
BlockNum? atBlock,
2526
}) async {
2627
final function = self.abi.functions[0];
2728
assert(checkSignature(function, 'dd62ed3e'));
@@ -36,10 +37,10 @@ class ERC20 extends web3.GeneratedContract {
3637
/// like the gas price, nonce and max gas. The `data` and `to` fields will be
3738
/// set by the contract.
3839
Future<String> approve(
39-
web3.EthereumAddress spender,
40+
EthereumAddress spender,
4041
BigInt amount, {
41-
required web3.Credentials credentials,
42-
web3.Transaction? transaction,
42+
required Credentials credentials,
43+
Transaction? transaction,
4344
}) async {
4445
final function = self.abi.functions[1];
4546
assert(checkSignature(function, '095ea7b3'));
@@ -52,10 +53,7 @@ class ERC20 extends web3.GeneratedContract {
5253
/// The optional [atBlock] parameter can be used to view historical data. When
5354
/// set, the function will be evaluated in the specified block. By default, the
5455
/// latest on-chain block will be used.
55-
Future<BigInt> balanceOf(
56-
web3.EthereumAddress account, {
57-
web3.BlockNum? atBlock,
58-
}) async {
56+
Future<BigInt> balanceOf(EthereumAddress account, {BlockNum? atBlock}) async {
5957
final function = self.abi.functions[2];
6058
assert(checkSignature(function, '70a08231'));
6159
final params = [account];
@@ -68,7 +66,7 @@ class ERC20 extends web3.GeneratedContract {
6866
/// The optional [atBlock] parameter can be used to view historical data. When
6967
/// set, the function will be evaluated in the specified block. By default, the
7068
/// latest on-chain block will be used.
71-
Future<BigInt> decimals({web3.BlockNum? atBlock}) async {
69+
Future<BigInt> decimals({BlockNum? atBlock}) async {
7270
final function = self.abi.functions[3];
7371
assert(checkSignature(function, '313ce567'));
7472
final params = [];
@@ -81,7 +79,7 @@ class ERC20 extends web3.GeneratedContract {
8179
/// The optional [atBlock] parameter can be used to view historical data. When
8280
/// set, the function will be evaluated in the specified block. By default, the
8381
/// latest on-chain block will be used.
84-
Future<String> name({web3.BlockNum? atBlock}) async {
82+
Future<String> name({BlockNum? atBlock}) async {
8583
final function = self.abi.functions[4];
8684
assert(checkSignature(function, '06fdde03'));
8785
final params = [];
@@ -94,7 +92,7 @@ class ERC20 extends web3.GeneratedContract {
9492
/// The optional [atBlock] parameter can be used to view historical data. When
9593
/// set, the function will be evaluated in the specified block. By default, the
9694
/// latest on-chain block will be used.
97-
Future<String> symbol({web3.BlockNum? atBlock}) async {
95+
Future<String> symbol({BlockNum? atBlock}) async {
9896
final function = self.abi.functions[5];
9997
assert(checkSignature(function, '95d89b41'));
10098
final params = [];
@@ -107,7 +105,7 @@ class ERC20 extends web3.GeneratedContract {
107105
/// The optional [atBlock] parameter can be used to view historical data. When
108106
/// set, the function will be evaluated in the specified block. By default, the
109107
/// latest on-chain block will be used.
110-
Future<BigInt> totalSupply({web3.BlockNum? atBlock}) async {
108+
Future<BigInt> totalSupply({BlockNum? atBlock}) async {
111109
final function = self.abi.functions[6];
112110
assert(checkSignature(function, '18160ddd'));
113111
final params = [];
@@ -121,10 +119,10 @@ class ERC20 extends web3.GeneratedContract {
121119
/// like the gas price, nonce and max gas. The `data` and `to` fields will be
122120
/// set by the contract.
123121
Future<String> transfer(
124-
web3.EthereumAddress recipient,
122+
EthereumAddress recipient,
125123
BigInt amount, {
126-
required web3.Credentials credentials,
127-
web3.Transaction? transaction,
124+
required Credentials credentials,
125+
Transaction? transaction,
128126
}) async {
129127
final function = self.abi.functions[7];
130128
assert(checkSignature(function, 'a9059cbb'));
@@ -137,35 +135,44 @@ class ERC20 extends web3.GeneratedContract {
137135
/// The optional [transaction] parameter can be used to override parameters
138136
/// like the gas price, nonce and max gas. The `data` and `to` fields will be
139137
/// set by the contract.
140-
Future<String> transferFrom(web3.EthereumAddress sender,
141-
web3.EthereumAddress recipient, BigInt amount,
142-
{required web3.Credentials credentials,
143-
web3.Transaction? transaction}) async {
138+
Future<String> transferFrom(
139+
EthereumAddress sender,
140+
EthereumAddress recipient,
141+
BigInt amount, {
142+
required Credentials credentials,
143+
Transaction? transaction,
144+
}) async {
144145
final function = self.abi.functions[8];
145146
assert(checkSignature(function, '23b872dd'));
146147
final params = [sender, recipient, amount];
147148
return write(credentials, transaction, function, params);
148149
}
149150

150151
/// Returns a live stream of all Approval events emitted by this contract.
151-
Stream<Approval> approvalEvents(
152-
{web3.BlockNum? fromBlock, web3.BlockNum? toBlock}) {
152+
Stream<Approval> approvalEvents({BlockNum? fromBlock, BlockNum? toBlock}) {
153153
final event = self.event('Approval');
154-
final filter = web3.FilterOptions.events(
155-
contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock);
156-
return client.events(filter).map((web3.FilterEvent result) {
154+
final filter = FilterOptions.events(
155+
contract: self,
156+
event: event,
157+
fromBlock: fromBlock,
158+
toBlock: toBlock,
159+
);
160+
return client.events(filter).map((FilterEvent result) {
157161
final decoded = event.decodeResults(result.topics!, result.data!);
158162
return Approval._(decoded);
159163
});
160164
}
161165

162166
/// Returns a live stream of all Transfer events emitted by this contract.
163-
Stream<Transfer> transferEvents(
164-
{web3.BlockNum? fromBlock, web3.BlockNum? toBlock}) {
167+
Stream<Transfer> transferEvents({BlockNum? fromBlock, BlockNum? toBlock}) {
165168
final event = self.event('Transfer');
166-
final filter = web3.FilterOptions.events(
167-
contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock);
168-
return client.events(filter).map((web3.FilterEvent result) {
169+
final filter = FilterOptions.events(
170+
contract: self,
171+
event: event,
172+
fromBlock: fromBlock,
173+
toBlock: toBlock,
174+
);
175+
return client.events(filter).map((FilterEvent result) {
169176
final decoded = event.decodeResults(result.topics!, result.data!);
170177
return Transfer._(decoded);
171178
});
@@ -175,15 +182,15 @@ class ERC20 extends web3.GeneratedContract {
175182
/// Emitted when the allowance of a [spender] for an [owner] is set by a call to [ERC20.approve]. [value] is the new allowance.
176183
class Approval {
177184
Approval._(List<dynamic> response)
178-
: owner = (response[0] as web3.EthereumAddress),
179-
spender = (response[1] as web3.EthereumAddress),
180-
value = (response[2] as BigInt);
185+
: owner = (response[0] as EthereumAddress),
186+
spender = (response[1] as EthereumAddress),
187+
value = (response[2] as BigInt);
181188

182189
/// The owner address.
183-
final web3.EthereumAddress owner;
190+
final EthereumAddress owner;
184191

185192
/// The spender address.
186-
final web3.EthereumAddress spender;
193+
final EthereumAddress spender;
187194

188195
/// Value.
189196
final BigInt value;
@@ -192,15 +199,15 @@ class Approval {
192199
/// Emitted when [value] tokens are moved from one account ([from]) to another ([to]). Note that [value] may be zero.
193200
class Transfer {
194201
Transfer._(List<dynamic> response)
195-
: from = (response[0] as web3.EthereumAddress),
196-
to = (response[1] as web3.EthereumAddress),
197-
value = (response[2] as BigInt);
202+
: from = (response[0] as EthereumAddress),
203+
to = (response[1] as EthereumAddress),
204+
value = (response[2] as BigInt);
198205

199206
/// From address.
200-
final web3.EthereumAddress from;
207+
final EthereumAddress from;
201208

202209
/// To address.
203-
final web3.EthereumAddress to;
210+
final EthereumAddress to;
204211

205212
/// Value.
206213
final BigInt value;

pubspec.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: erc20
22
description: Interface of the ERC20 standard as defined in the EIP-20 Token Standard.
3-
version: 1.0.1
3+
version: 2.0.0
44
homepage: https://pwa.ir
55
repository: https://github.com/xclud/dart_erc20/
66

77
environment:
8-
sdk: ">=2.12.0 <3.0.0"
8+
sdk: ">=2.12.0 <4.0.0"
99

1010
dependencies:
11-
web3dart: ^2.5.2
11+
web3dart: ^3.0.0
12+
wallet: ^0.0.17
1213

1314
dev_dependencies:
14-
test: ^1.22.0
15-
lints: ^2.0.0
16-
http: ^0.13.5
15+
test: ^1.25.0
16+
lints: ^5.1.0
17+
http: ^1.0.0

test/erc20_test.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:test/test.dart';
22

33
import 'package:http/http.dart';
44
import 'package:web3dart/web3dart.dart';
5+
import 'package:wallet/wallet.dart';
56

67
import 'package:erc20/erc20.dart';
78

@@ -18,7 +19,9 @@ void main() {
1819

1920
setUpAll(() {
2021
client = Web3Client(
21-
'https://mainnet.infura.io/v3/$infuraProjectId', Client());
22+
'https://mainnet.infura.io/v3/$infuraProjectId',
23+
Client(),
24+
);
2225
});
2326

2427
// ignore: unnecessary_lambdas, https://github.com/dart-lang/linter/issues/2670
@@ -27,7 +30,8 @@ void main() {
2730
test('erc20 get token info', () async {
2831
final shibaInu = ERC20(
2932
address: EthereumAddress.fromHex(
30-
'0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce'),
33+
'0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce',
34+
),
3135
client: client,
3236
);
3337

@@ -43,19 +47,24 @@ void main() {
4347
test('erc20 get balance', () async {
4448
final shibaInu = ERC20(
4549
address: EthereumAddress.fromHex(
46-
'0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce'),
50+
'0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce',
51+
),
4752
client: client,
4853
);
4954

50-
final balance = await shibaInu.balanceOf(EthereumAddress.fromHex(
51-
'0xdead000000000000000042069420694206942069'));
55+
final balance = await shibaInu.balanceOf(
56+
EthereumAddress.fromHex('0xdead000000000000000042069420694206942069'),
57+
);
5258

53-
expect(balance >= BigInt.parse('410243042034234643784017156276017'),
54-
isTrue);
59+
expect(
60+
balance >= BigInt.parse('410243042034234643784017156276017'),
61+
isTrue,
62+
);
5563
});
5664
},
57-
skip: infuraProjectId == null || infuraProjectId.length < 32
58-
? 'Tests require the INFURA_ID environment variable'
59-
: null,
65+
skip:
66+
infuraProjectId == null || infuraProjectId.length < 32
67+
? 'Tests require the INFURA_ID environment variable'
68+
: null,
6069
);
6170
}

0 commit comments

Comments
 (0)