@alephium/web3 0.1.0 → 0.2.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +7 -0
  4. package/contracts/{greeter_interface.ral → greeter/greeter_interface.ral} +1 -0
  5. package/contracts/greeter_main.ral +2 -4
  6. package/dist/alephium-web3.min.js +1 -1
  7. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  8. package/dist/alephium-web3.min.js.map +1 -1
  9. package/dist/scripts/create-project.js +3 -2
  10. package/dist/src/api/api-alephium.d.ts +58 -13
  11. package/dist/src/api/api-alephium.js +19 -3
  12. package/dist/src/api/api-explorer.d.ts +32 -16
  13. package/dist/src/api/api-explorer.js +26 -0
  14. package/dist/src/api/index.d.ts +2 -2
  15. package/dist/src/api/index.js +18 -3
  16. package/dist/src/contract/contract.d.ts +105 -48
  17. package/dist/src/contract/contract.js +362 -189
  18. package/dist/src/contract/events.d.ts +7 -25
  19. package/dist/src/contract/events.js +18 -31
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/global.d.ts +4 -0
  22. package/dist/src/global.js +38 -0
  23. package/dist/src/index.d.ts +3 -0
  24. package/dist/src/index.js +21 -1
  25. package/dist/src/signer/index.d.ts +0 -1
  26. package/dist/src/signer/index.js +5 -2
  27. package/dist/src/signer/signer.d.ts +1 -1
  28. package/dist/src/signer/signer.js +8 -3
  29. package/dist/src/transaction/index.d.ts +1 -0
  30. package/dist/src/{test → transaction}/index.js +6 -13
  31. package/dist/src/transaction/status.d.ts +10 -0
  32. package/dist/src/transaction/status.js +48 -0
  33. package/dist/src/utils/index.d.ts +1 -2
  34. package/dist/src/utils/index.js +6 -3
  35. package/dist/src/utils/subscription.d.ts +23 -0
  36. package/dist/src/utils/subscription.js +53 -0
  37. package/dist/src/utils/utils.d.ts +5 -2
  38. package/dist/src/utils/utils.js +25 -16
  39. package/jest-config.json +11 -0
  40. package/package.json +7 -35
  41. package/scripts/create-project.ts +3 -2
  42. package/src/api/api-alephium.ts +73 -8
  43. package/src/api/api-explorer.ts +30 -0
  44. package/src/api/index.ts +13 -3
  45. package/src/contract/contract.ts +512 -279
  46. package/src/contract/events.ts +21 -48
  47. package/src/{utils/transaction.ts → global.ts} +14 -15
  48. package/src/index.ts +4 -0
  49. package/src/signer/index.ts +0 -1
  50. package/src/signer/signer.ts +4 -3
  51. package/src/{utils/password-crypto.test.ts → transaction/index.ts} +1 -9
  52. package/src/transaction/status.ts +58 -0
  53. package/src/utils/index.ts +1 -2
  54. package/src/utils/subscription.ts +72 -0
  55. package/src/utils/utils.ts +16 -8
  56. package/templates/base/package.json +2 -2
  57. package/templates/base/src/greeter.ts +8 -7
  58. package/templates/react/package.json +2 -2
  59. package/templates/react/src/App.tsx +2 -2
  60. package/.eslintrc.json +0 -21
  61. package/LICENSE +0 -165
  62. package/contracts/add.ral +0 -16
  63. package/contracts/greeter.ral +0 -7
  64. package/contracts/main.ral +0 -6
  65. package/contracts/sub.ral +0 -9
  66. package/dist/src/signer/node-wallet.d.ts +0 -13
  67. package/dist/src/signer/node-wallet.js +0 -60
  68. package/dist/src/test/index.d.ts +0 -7
  69. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  70. package/dist/src/test/privatekey-wallet.js +0 -68
  71. package/dist/src/utils/password-crypto.d.ts +0 -2
  72. package/dist/src/utils/password-crypto.js +0 -69
  73. package/dist/src/utils/transaction.d.ts +0 -2
  74. package/dist/src/utils/transaction.js +0 -58
  75. package/gitignore +0 -10
  76. package/src/contract/ralph.test.ts +0 -178
  77. package/src/fixtures/address.json +0 -36
  78. package/src/fixtures/balance.json +0 -9
  79. package/src/fixtures/self-clique.json +0 -19
  80. package/src/fixtures/transaction.json +0 -13
  81. package/src/fixtures/transactions.json +0 -179
  82. package/src/signer/fixtures/genesis.json +0 -26
  83. package/src/signer/fixtures/wallets.json +0 -26
  84. package/src/signer/node-wallet.ts +0 -74
  85. package/src/test/index.ts +0 -32
  86. package/src/test/privatekey-wallet.ts +0 -58
  87. package/src/utils/address.test.ts +0 -47
  88. package/src/utils/djb2.test.ts +0 -35
  89. package/src/utils/password-crypto.ts +0 -77
  90. package/src/utils/transaction.test.ts +0 -50
  91. package/src/utils/utils.test.ts +0 -160
  92. package/test/contract.test.ts +0 -161
  93. package/test/events.test.ts +0 -139
@@ -16,64 +16,33 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import EventEmitter from 'eventemitter3'
20
- import { node } from '../api'
21
- import { NodeProvider } from '../api'
19
+ import { ContractEvent } from '../api/api-alephium'
20
+ import { Subscription, SubscribeOptions } from '../utils'
22
21
 
23
- type EventCallback = (event: node.ContractEvent) => Promise<void>
24
- type ErrorCallback = (error: any, subscription: Subscription) => Promise<void>
25
-
26
- export interface SubscribeOptions {
27
- provider: NodeProvider
28
- contractAddress: string
29
- fromCount?: number
30
- pollingInterval: number
31
- eventCallback: EventCallback
32
- errorCallback: ErrorCallback
33
- }
34
-
35
- export class Subscription {
36
- provider: NodeProvider
22
+ export class EventSubscription extends Subscription<ContractEvent> {
37
23
  readonly contractAddress: string
38
- pollingInterval: number
39
-
40
24
  private fromCount: number
41
- private eventCallback: EventCallback
42
- private errorCallback: ErrorCallback
43
- private task: ReturnType<typeof setTimeout> | undefined
44
- private cancelled: boolean
45
- private eventEmitter: EventEmitter
46
25
 
47
- constructor(options: SubscribeOptions) {
48
- this.provider = options.provider
49
- this.contractAddress = options.contractAddress
50
- this.fromCount = typeof options.fromCount === 'undefined' ? 0 : options.fromCount
51
- this.pollingInterval = options.pollingInterval
52
- this.eventCallback = options.eventCallback
53
- this.errorCallback = options.errorCallback
54
- this.task = undefined
55
- this.cancelled = false
26
+ constructor(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number) {
27
+ super(options)
28
+ this.contractAddress = contractAddress
29
+ this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount
56
30
 
57
- this.eventEmitter = new EventEmitter()
31
+ this.startPolling()
32
+ }
33
+
34
+ override startPolling(): void {
58
35
  this.eventEmitter.on('tick', async () => {
59
- await this.fetchEvents()
36
+ await this.polling()
60
37
  })
61
38
  this.eventEmitter.emit('tick')
62
39
  }
63
40
 
64
- unsubscribe(): void {
65
- this.eventEmitter.removeAllListeners()
66
- this.cancelled = true
67
- if (typeof this.task !== 'undefined') {
68
- clearTimeout(this.task)
69
- }
70
- }
71
-
72
41
  currentEventCount(): number {
73
42
  return this.fromCount
74
43
  }
75
44
 
76
- private async fetchEvents() {
45
+ override async polling(): Promise<void> {
77
46
  try {
78
47
  const events = await this.provider.events.getEventsContractContractaddress(this.contractAddress, {
79
48
  start: this.fromCount
@@ -87,16 +56,20 @@ export class Subscription {
87
56
  return
88
57
  }
89
58
 
90
- const promises = events.events.map((event) => this.eventCallback(event))
59
+ const promises = events.events.map((event) => this.messageCallback(event))
91
60
  await Promise.all(promises)
92
61
  this.fromCount = events.nextStart
93
- await this.fetchEvents()
62
+ await this.polling()
94
63
  } catch (err) {
95
64
  await this.errorCallback(err, this)
96
65
  }
97
66
  }
98
67
  }
99
68
 
100
- export function subscribe(options: SubscribeOptions): Subscription {
101
- return new Subscription(options)
69
+ export function subscribeToEvents(
70
+ options: SubscribeOptions<ContractEvent>,
71
+ contractAddress: string,
72
+ fromCount?: number
73
+ ): EventSubscription {
74
+ return new EventSubscription(options, contractAddress, fromCount)
102
75
  }
@@ -16,24 +16,23 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { ec as EC } from 'elliptic'
19
+ import { NodeProvider } from './api'
20
20
 
21
- import * as utils from './utils'
21
+ let _currentNodeProvider: NodeProvider | undefined = undefined
22
22
 
23
- const ec = new EC('secp256k1')
24
-
25
- export function transactionSign(txHash: string, privateKey: string): string {
26
- const keyPair = ec.keyFromPrivate(privateKey)
27
- const signature = keyPair.sign(txHash)
28
-
29
- return utils.signatureEncode(signature)
23
+ export function setCurrentNodeProvider(provider: NodeProvider): void
24
+ export function setCurrentNodeProvider(baseUrl: string, apiKey?: string): void
25
+ export function setCurrentNodeProvider(provider: NodeProvider | string, apiKey?: string): void {
26
+ if (typeof provider == 'string') {
27
+ _currentNodeProvider = new NodeProvider(provider, apiKey)
28
+ } else {
29
+ _currentNodeProvider = provider
30
+ }
30
31
  }
31
32
 
32
- export function transactionVerifySignature(txHash: string, publicKey: string, signature: string): boolean {
33
- try {
34
- const key = ec.keyFromPublic(publicKey, 'hex')
35
- return key.verify(txHash, utils.signatureDecode(ec, signature))
36
- } catch (error) {
37
- return false
33
+ export function getCurrentNodeProvider(): NodeProvider {
34
+ if (typeof _currentNodeProvider === 'undefined') {
35
+ throw Error('No node provider is set.')
38
36
  }
37
+ return _currentNodeProvider
39
38
  }
package/src/index.ts CHANGED
@@ -20,5 +20,9 @@ export * from './api'
20
20
  export * from './contract'
21
21
  export * from './signer'
22
22
  export * from './utils'
23
+ export * from './transaction'
23
24
 
24
25
  export * from './constants'
26
+ export * as web3 from './global'
27
+
28
+ export * as utils from './utils'
@@ -17,4 +17,3 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
19
  export * from './signer'
20
- export * from './node-wallet'
@@ -23,6 +23,7 @@ import * as utils from '../utils'
23
23
  import { Eq, assertType } from '../utils'
24
24
  import blake from 'blakejs'
25
25
  import { Token } from '../api/api-alephium'
26
+ import { getCurrentNodeProvider } from '../global'
26
27
 
27
28
  const ec = new EC('secp256k1')
28
29
 
@@ -42,7 +43,7 @@ export interface Account {
42
43
 
43
44
  export type SubmitTx = { submitTx?: boolean }
44
45
  export type SignerAddress = { signerAddress: string }
45
- type TxBuildParams<T> = Omit<T, 'fromPublicKey'> & SignerAddress & SubmitTx
46
+ type TxBuildParams<T> = Omit<T, 'fromPublicKey' | 'targetBlockHash'> & SignerAddress & SubmitTx
46
47
 
47
48
  export type GetAccountsParams = undefined
48
49
  export type GetAccountsResult = Account[]
@@ -167,8 +168,8 @@ export abstract class SignerWithNodeProvider implements SignerProvider {
167
168
  }
168
169
  }
169
170
 
170
- constructor(provider: NodeProvider, alwaysSubmitTx: boolean) {
171
- this.provider = provider
171
+ constructor(alwaysSubmitTx: boolean) {
172
+ this.provider = getCurrentNodeProvider()
172
173
  this.alwaysSubmitTx = alwaysSubmitTx
173
174
  }
174
175
 
@@ -16,12 +16,4 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- import { decrypt } from './password-crypto'
20
-
21
- describe('password-crypto', () => {
22
- it('should raise an error if payload version is not 1', () => {
23
- const password = 'passw0rd'
24
- const payloadRaw = '{"version":2}'
25
- expect(() => decrypt(password, payloadRaw)).toThrow('Invalid version: got 2, expected: 1')
26
- })
27
- })
19
+ export * from './status'
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import { TxStatus } from '../api/api-alephium'
20
+ import { Subscription, SubscribeOptions } from '../utils'
21
+
22
+ export class TxStatusSubscription extends Subscription<TxStatus> {
23
+ readonly txId: string
24
+ readonly fromGroup?: number
25
+ readonly toGroup?: number
26
+
27
+ constructor(options: SubscribeOptions<TxStatus>, txId: string, fromGroup?: number, toGroup?: number) {
28
+ super(options)
29
+ this.txId = txId
30
+ this.fromGroup = fromGroup
31
+ this.toGroup = toGroup
32
+
33
+ this.startPolling()
34
+ }
35
+
36
+ override async polling(): Promise<void> {
37
+ try {
38
+ const txStatus = await this.provider.transactions.getTransactionsStatus({
39
+ txId: this.txId,
40
+ fromGroup: this.fromGroup,
41
+ toGroup: this.toGroup
42
+ })
43
+
44
+ await this.messageCallback(txStatus)
45
+ } catch (err) {
46
+ await this.errorCallback(err, this)
47
+ }
48
+ }
49
+ }
50
+
51
+ export function subscribeToTxStatus(
52
+ options: SubscribeOptions<TxStatus>,
53
+ txId: string,
54
+ fromGroup?: number,
55
+ toGroup?: number
56
+ ): TxStatusSubscription {
57
+ return new TxStatusSubscription(options, txId, fromGroup, toGroup)
58
+ }
@@ -19,6 +19,5 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
19
  export * from './address'
20
20
  export * from './bs58'
21
21
  export * from './djb2'
22
- export * from './password-crypto'
23
- export * from './transaction'
24
22
  export * from './utils'
23
+ export * from './subscription'
@@ -0,0 +1,72 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ import EventEmitter from 'eventemitter3'
20
+ import { getCurrentNodeProvider } from '../global'
21
+ import { NodeProvider } from '../api'
22
+
23
+ type MessageCallback<Message> = (message: Message) => Promise<void>
24
+ type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>
25
+
26
+ export interface SubscribeOptions<Message> {
27
+ pollingInterval: number
28
+ messageCallback: MessageCallback<Message>
29
+ errorCallback: ErrorCallback<Message>
30
+ }
31
+
32
+ export abstract class Subscription<Message> {
33
+ provider: NodeProvider
34
+ pollingInterval: number
35
+
36
+ protected messageCallback: MessageCallback<Message>
37
+ protected errorCallback: ErrorCallback<Message>
38
+ protected task: ReturnType<typeof setTimeout> | undefined
39
+ protected eventEmitter: EventEmitter
40
+ protected cancelled: boolean
41
+
42
+ constructor(options: SubscribeOptions<Message>) {
43
+ this.provider = getCurrentNodeProvider()
44
+ this.pollingInterval = options.pollingInterval
45
+ this.messageCallback = options.messageCallback
46
+ this.errorCallback = options.errorCallback
47
+ this.task = undefined
48
+ this.cancelled = false
49
+ this.eventEmitter = new EventEmitter()
50
+ }
51
+
52
+ startPolling(): void {
53
+ this.eventEmitter.on('tick', async () => {
54
+ await this.polling()
55
+
56
+ if (!this.cancelled) {
57
+ this.task = setTimeout(() => this.eventEmitter.emit('tick'), this.pollingInterval)
58
+ }
59
+ })
60
+ this.eventEmitter.emit('tick')
61
+ }
62
+
63
+ unsubscribe(): void {
64
+ this.eventEmitter.removeAllListeners()
65
+ this.cancelled = true
66
+ if (typeof this.task !== 'undefined') {
67
+ clearTimeout(this.task)
68
+ }
69
+ }
70
+
71
+ abstract polling(): Promise<void>
72
+ }
@@ -51,7 +51,7 @@ export function signatureEncode(signature: EC.Signature): string {
51
51
  }
52
52
 
53
53
  // the signature should be in hex string format for 64 bytes
54
- export const signatureDecode = (ec: EC, signature: string): SignatureInput => {
54
+ export function signatureDecode(ec: EC, signature: string): SignatureInput {
55
55
  if (signature.length !== 128) {
56
56
  throw new Error('Invalid signature length')
57
57
  }
@@ -66,7 +66,7 @@ export const signatureDecode = (ec: EC, signature: string): SignatureInput => {
66
66
  }
67
67
  }
68
68
 
69
- const xorByte = (intValue: number) => {
69
+ export function xorByte(intValue: number): number {
70
70
  const byte0 = (intValue >> 24) & 0xff
71
71
  const byte1 = (intValue >> 16) & 0xff
72
72
  const byte2 = (intValue >> 8) & 0xff
@@ -85,7 +85,7 @@ enum AddressType {
85
85
  P2C = 0x03
86
86
  }
87
87
 
88
- export const groupOfAddress = (address: string): number => {
88
+ export function groupOfAddress(address: string): number {
89
89
  const decoded = bs58.decode(address)
90
90
 
91
91
  if (decoded.length == 0) throw new Error('Address string is empty')
@@ -103,7 +103,7 @@ export const groupOfAddress = (address: string): number => {
103
103
  }
104
104
  }
105
105
 
106
- const groupOfAddressBytes = (bytes: Uint8Array): number => {
106
+ function groupOfAddressBytes(bytes: Uint8Array): number {
107
107
  const hint = djb2(bytes) | 1
108
108
  const hash = xorByte(hint)
109
109
  const group = hash % TOTAL_NUMBER_OF_GROUPS
@@ -111,7 +111,7 @@ const groupOfAddressBytes = (bytes: Uint8Array): number => {
111
111
  }
112
112
 
113
113
  // Pay to public key hash address
114
- const groupOfP2pkhAddress = (address: Uint8Array): number => {
114
+ function groupOfP2pkhAddress(address: Uint8Array): number {
115
115
  if (address.length != 32) {
116
116
  throw new Error(`Invalid p2pkh address length: ${address.length}`)
117
117
  }
@@ -120,7 +120,7 @@ const groupOfP2pkhAddress = (address: Uint8Array): number => {
120
120
  }
121
121
 
122
122
  // Pay to multiple public key hash address
123
- const groupOfP2mpkhAddress = (address: Uint8Array): number => {
123
+ function groupOfP2mpkhAddress(address: Uint8Array): number {
124
124
  if ((address.length - 2) % 32 != 0) {
125
125
  throw new Error(`Invalid p2mpkh address length: ${address.length}`)
126
126
  }
@@ -129,7 +129,7 @@ const groupOfP2mpkhAddress = (address: Uint8Array): number => {
129
129
  }
130
130
 
131
131
  // Pay to script hash address
132
- const groupOfP2shAddress = (address: Uint8Array): number => {
132
+ function groupOfP2shAddress(address: Uint8Array): number {
133
133
  return groupOfAddressBytes(address)
134
134
  }
135
135
 
@@ -190,7 +190,7 @@ export function contractIdFromTx(txId: string, outputIndex: number): string {
190
190
  }
191
191
 
192
192
  export function subContractId(parentContractId: string, pathInHex: string): string {
193
- const data = Buffer.concat([hexToBinUnsafe(pathInHex), hexToBinUnsafe(parentContractId)])
193
+ const data = Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)])
194
194
 
195
195
  return binToHex(blake.blake2b(blake.blake2b(data, undefined, 32), undefined, 32))
196
196
  }
@@ -203,6 +203,14 @@ export function stringToHex(str: string): string {
203
203
  return hex
204
204
  }
205
205
 
206
+ export function hexToString(str: string): string {
207
+ return Buffer.from(str, 'hex').toString()
208
+ }
209
+
210
+ export function timeout(ms: number): Promise<void> {
211
+ return new Promise((resolve) => setTimeout(resolve, ms))
212
+ }
213
+
206
214
  type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
207
215
  export type Eq<X, Y> = _Eq<{ [P in keyof X]: X[P] }, { [P in keyof Y]: Y[P] }>
208
216
  // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
@@ -3,7 +3,7 @@
3
3
  "version": "0.1.0",
4
4
  "license": "GPL",
5
5
  "config": {
6
- "alephium_version": "1.4.0-rc2"
6
+ "alephium_version": "1.5.0-rc7"
7
7
  },
8
8
  "scripts": {
9
9
  "build": "rm -rf dist && npx tsc --build .",
@@ -12,7 +12,7 @@
12
12
  "stop-devnet": "node scripts/stop-devnet.js"
13
13
  },
14
14
  "dependencies": {
15
- "@alephium/web3": "0.1.0"
15
+ "@alephium/web3": "0.2.0-rc.9"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/elliptic": "^6.4.13",
@@ -2,21 +2,22 @@
2
2
  * greeter.ts
3
3
  */
4
4
 
5
- import { NodeProvider, Contract, Script, TestContractParams } from '@alephium/web3'
6
- import { testWallet } from '@alephium/web3/test'
5
+ import { TestContractParams, web3, Project } from '@alephium/web3'
6
+ import { testNodeWallet } from '@alephium/web3/test'
7
7
 
8
8
  async function greet() {
9
- const provider = new NodeProvider('http://127.0.0.1:22973')
9
+ web3.setCurrentNodeProvider('http://127.0.0.1:22973')
10
+ await Project.build()
10
11
 
11
- const greeter = await Contract.fromSource(provider, 'greeter.ral')
12
+ const greeter = Project.contract('greeter/greeter.ral')
12
13
 
13
14
  const testParams: TestContractParams = {
14
15
  initialFields: { btcPrice: 1 }
15
16
  }
16
- const testResult = await greeter.testPublicMethod(provider, 'greet', testParams)
17
+ const testResult = await greeter.testPublicMethod('greet', testParams)
17
18
  console.log(testResult)
18
19
 
19
- const signer = await testWallet(provider)
20
+ const signer = await testNodeWallet()
20
21
 
21
22
  const deployTx = await greeter.transactionForDeployment(signer, { initialFields: testParams.initialFields })
22
23
  const greeterContractId = deployTx.contractId
@@ -26,7 +27,7 @@ async function greet() {
26
27
  const submitResult = await signer.submitTransaction(deployTx.unsignedTx, deployTx.txId)
27
28
  console.log(submitResult)
28
29
 
29
- const main = await Script.fromSource(provider, 'greeter_main.ral')
30
+ const main = Project.script('greeter_main.ral')
30
31
 
31
32
  const mainScriptTx = await main.transactionForDeployment(signer, {
32
33
  initialFields: { greeterContractId: greeterContractId }
@@ -2,7 +2,7 @@
2
2
  "name": "my-dapp",
3
3
  "version": "0.1.0",
4
4
  "config": {
5
- "alephium_version": "1.4.0-rc2"
5
+ "alephium_version": "1.5.0-rc7"
6
6
  },
7
7
  "dependencies": {
8
8
  "@testing-library/jest-dom": "^5.16.4",
@@ -12,7 +12,7 @@
12
12
  "@types/node": "^16.11.26",
13
13
  "@types/react": "^18.0.3",
14
14
  "@types/react-dom": "^18.0.0",
15
- "@alephium/web3": "0.1.0",
15
+ "@alephium/web3": "0.2.0-rc.9",
16
16
  "react": "^18.0.0",
17
17
  "react-dom": "^18.0.0",
18
18
  "react-scripts": "5.0.1",
@@ -1,12 +1,12 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import './App.css'
3
3
 
4
- import { explorer, Contract, Script } from '@alephium/web3'
4
+ import { ExplorerProvider, Contract, Script } from '@alephium/web3'
5
5
  import contractJson from './artifacts/greeter.ral.json'
6
6
  import scriptJson from './artifacts/greeter_main.ral.json'
7
7
 
8
8
  function Dashboard() {
9
- const api = new explorer.Api<null>({ baseUrl: 'https://mainnet-backend.alephium.org' })
9
+ const api = new ExplorerProvider('https://mainnet-backend.alephium.org')
10
10
  const contract = Contract.fromJson(contractJson).toString()
11
11
  const script = Script.fromJson(scriptJson).toString()
12
12
  const [blocks, setBlocks] = useState('')
package/.eslintrc.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "plugins": ["security", "header"],
3
- "extends": [
4
- "prettier",
5
- "plugin:prettier/recommended",
6
- "plugin:security/recommended",
7
- "plugin:@typescript-eslint/recommended"
8
- ],
9
- "parser": "@typescript-eslint/parser",
10
- "rules": {
11
- "header/header": [2, "scripts/header.js"]
12
- },
13
- "overrides": [
14
- {
15
- "files": ["*.ts"],
16
- "rules": {
17
- "security/detect-non-literal-fs-filename": "off"
18
- }
19
- }
20
- ]
21
- }