-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.ts
40 lines (35 loc) · 1.11 KB
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { actionCreators, encodeSignedDelegate } from '@near-js/transactions';
import { getAccount } from './util';
const CLIENT_ID = 'the-user.testnet';
const CLIENT_PRIVATE_KEY =
'ed25519:4PcuqzFyK8yas151xKBoBbUe5DLCd4RcpekW5rjKTsUtabkvGqwacgmnBECDdzEQAvozG5spguF2yp5knjNjDHAt';
const NETWORK_ID = 'testnet';
const CONTRACT_ID = 'hello.near-examples.testnet';
const SERVER_URL = 'http://localhost:5000/';
async function sendRelay() {
const action = actionCreators.functionCall(
'set_greeting',
{
greeting: 'hello',
},
3000000000000n,
);
const account = await getAccount(NETWORK_ID, CLIENT_ID, CLIENT_PRIVATE_KEY);
const signedDelegate = await account.signedDelegate({
actions: [action],
blockHeightTtl: 120,
receiverId: CONTRACT_ID,
});
const res = await fetch(SERVER_URL, {
method: 'POST',
mode: 'cors',
body: JSON.stringify([Array.from(encodeSignedDelegate(signedDelegate))]),
headers: new Headers({ 'Content-Type': 'application/json' }),
});
if (res.ok) {
console.log(await res.json());
} else {
console.error(await res.text());
}
}
sendRelay();