-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestAmeViem.js
77 lines (69 loc) · 1.85 KB
/
testAmeViem.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { AmeViem } from "./src/index";
import { privateKeyToAccount } from "viem/accounts";
import dotenv from "dotenv/config";
async function testAmeViem() {
const localhost = {
id: 31337,
rpcUrls: {
default: { http: ["http://127.0.0.1:8545"] },
},
};
const ameViem = new AmeViem(
localhost,
"0xF6a9ADA5eB198aFac770D6828b2d3C15FF07c5cE"
);
//component options, method names, data types
const options = await ameViem.getComponentOptions();
var methods = [];
for (var methodType of options) {
methodType = parseInt(methodType);
var methodNames = await ameViem.getComponentMethods(methodType);
console.log("methodNames", methodNames);
for (var methodName of methodNames) {
var dataType = await ameViem.getMethodReqAndRes(methodName);
methods.push({
methodName: methodName,
methodType: methodType,
dataType: dataType,
});
}
}
//get request
var encode = ameViem.encodeRequestParams(
[{ name: "address", type: "address" }],
["0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"]
);
const getReqRes = await ameViem.sendGetRequest("getUser", encode);
var account = privateKeyToAccount(process.env.PRIVATE_KEY);
var postReqEncode = ameViem.encodeRequestParams(
[
{ name: "username", type: "string" },
{ name: "age", type: "uint256" },
],
["alice2", "20"]
);
//post request
const postReqRes = await ameViem.sendPostAndPutRequest(
"post",
"createUser",
postReqEncode,
account,
"0"
);
//put request
var putReqEncode = ameViem.encodeRequestParams(
[
{ name: "from", type: "address" },
{ name: "name", type: "string" },
],
[account.address, "bob"]
);
const putReqRes = await ameViem.sendPostAndPutRequest(
"put",
"updateUserName",
putReqEncode,
account,
"0"
);
}
testAmeViem();