Skip to content

Commit 57b8008

Browse files
authored
docs: fix and improve code examples in go + typescript sdks (#8)
* feat: export additional types * docs: fix and improve code examples * docs: fix and improve code examples * docs: reference interface in custom signer code example * docs: update changelog
1 parent ef3fc8a commit 57b8008

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

go/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ account := radius.NewAccount(
4343

4444
```go
4545
// Send 100 tokens to another account
46-
recipient := radius.AddressFromHex("0x...")
46+
recipient, err := radius.AddressFromHex("0x...")
4747
amount := big.NewInt(100)
4848
receipt, err := account.Send(context.Background(), client, recipient, amount)
4949
if err != nil {
5050
log.Fatal(err)
5151
}
5252

53-
log.Printf("Transaction hash: %v", receipt.TxHash.Hex())
53+
log.Printf("Transaction hash: %s", receipt.TxHash.Hex())
5454
```
5555

5656
### Deploy a Smart Contract
@@ -73,7 +73,7 @@ contract, err := client.DeployContract(
7373

7474
```go
7575
// Reference an existing contract
76-
address := radius.AddressFromHex("0x...")
76+
address, err := radius.AddressFromHex("0x...")
7777
abi := radius.ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`)
7878
contract := radius.NewContract(address, abi)
7979

@@ -91,12 +91,15 @@ log.Printf("Stored value: %v", result[0])
9191
### Custom Transaction Signing
9292

9393
```go
94-
// Use an external signer (e.g., Clef)
95-
address := radius.AddressFromHex("0x...")
96-
clefSigner, err := radius.NewClefSigner(address, client, "http://localhost:8550")
97-
account := radius.NewAccount(radius.WithSigner(clefSigner))
94+
type MyCustomSigner struct{
95+
// ...
96+
}
97+
func (s *MyCustomSigner) Address() radius.Address { /* ... */ }
98+
func (s *MyCustomSigner) ChainID() *big.Int { /* ... */ }
99+
func (s *MyCustomSigner) Hash(tx *radius.Transaction) radius.Hash { /* ... */ }
100+
func (s *MyCustomSigner) SignMessage(message []byte) ([]byte, error) { /* ... */ }
101+
func (s *MyCustomSigner) SignTransaction(tx *radius.Transaction) (*radius.SignedTransaction, error) { /* ... */ }
98102

99-
// Or create a custom signer
100103
customSigner := &MyCustomSigner{}
101104
customSignerAccount := radius.NewAccount(radius.WithSigner(customSigner))
102105
```
@@ -109,7 +112,7 @@ client, err := radius.NewClient("https://your-radius-endpoint",
109112
log.Printf(format, args...)
110113
}),
111114
radius.WithInterceptor(func(reqBody string, resp *http.Response) (*http.Response, error) {
112-
// Process or log responses
115+
// Examine request body, modify response, etc.
113116
return resp, nil
114117
}),
115118
)

typescript/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to the Radius TypeScript SDK will be documented in this file
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Type exports for `BigNumberish`, `BytesLike`, and `HttpClient`, required for custom `Signer` implementations
10+
11+
### Security
12+
- Added pnpm override for `esbuild` requiring v0.25.0 or above, to address a known security vulnerability
13+
714
## 1.0.0
815
### Added
916
- Initial SDK implementation

typescript/README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ way to interact with the Radius platform.
1414
## Requirements
1515

1616
- Node.js >= 20.12.2
17-
- npm, yarn, or pnpm
1817

1918
## Installation
2019

@@ -62,7 +61,7 @@ console.log('Transaction hash:', receipt.txHash.hex());
6261
import { ABIFromJSON, BytecodeFromHex } from '@radiustechsystems/sdk';
6362

6463
// Parse ABI and bytecode
65-
const abi = new ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
64+
const abi = ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
6665
const bytecode = BytecodeFromHex('608060405234801561001057600080fd5b50610150806100...');
6766

6867
// Deploy the contract
@@ -76,7 +75,7 @@ import { NewContract, AddressFromHex, ABIFromJSON } from '@radiustechsystems/sdk
7675

7776
// Reference an existing contract
7877
const address = AddressFromHex('0x...');
79-
const abi = new ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
78+
const abi = ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
8079
const contract = NewContract(address, abi);
8180

8281
// Write to the contract
@@ -93,16 +92,18 @@ console.log('Stored value:', result[0]);
9392
### Custom Transaction Signing
9493

9594
```typescript
96-
import { NewClefSigner, NewAccount, withSigner, AddressFromHex } from '@radiustechsystems/sdk';
97-
98-
// Use an external signer (e.g., Clef)
99-
const address = AddressFromHex('0x...');
100-
const clefSigner = NewClefSigner(address, client, 'http://localhost:8550');
101-
const account = await NewAccount(withSigner(clefSigner));
102-
103-
// Or create a custom signer
104-
const customSigner = new MyCustomSigner();
105-
const customSignerAccount = NewAccount(withSigner(customSigner));
95+
import { Address, BigNumberish, BytesLike, Hash, SignedTransaction, Signer, Transaction } from '@radiustechsystems/sdk';
96+
97+
class MyCustomSigner implements Signer {
98+
address(): Address { /* ... */ }
99+
chainID(): BigNumberish { /* ... */ }
100+
hash(transaction: Transaction): Hash { /* ... */ }
101+
signMessage(message: BytesLike): Promise<Uint8Array> { /* ... */ }
102+
signTransaction(transaction: Transaction): Promise<SignedTransaction> { /* ... */ }
103+
constructor(...args) { /* ... */ }
104+
}
105+
const signer = new MyCustomSigner(...args);
106+
const account = NewAccount(withSigner(signer));
106107
```
107108

108109
### Logging and Request Interceptors
@@ -115,7 +116,7 @@ const client = await NewClient('https://your-radius-endpoint',
115116
console.log(message, data);
116117
}),
117118
withInterceptor(async (reqBody, response) => {
118-
// Process or log responses
119+
// Examine request body, modify response, etc.
119120
return response;
120121
})
121122
);
@@ -127,7 +128,9 @@ const client = await NewClient('https://your-radius-endpoint',
127128
import { NewClient, withHttpClient } from '@radiustechsystems/sdk';
128129

129130
const client = await NewClient('https://your-radius-endpoint',
130-
withHttpClient(customHttpClient)
131+
withHttpClient(async (url: string | URL | Request, init?: RequestInit | undefined): Promise<Response> => {
132+
// Make a custom HTTP request, or use a library like axios
133+
})
131134
);
132135
```
133136

typescript/radius/sdk.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { Account } from '../src/accounts';
22
import type { AccountOption } from '../src/accounts';
33
import { withPrivateKey, withSigner } from '../src/accounts';
4-
import { ClefSigner } from '../src/auth';
5-
import { PrivateKeySigner } from '../src/auth';
6-
import type { Signer, SignerClient } from '../src/auth';
7-
import { Client } from '../src/client';
8-
import type { ClientOption } from '../src/client';
4+
import { ClefSigner, PrivateKeySigner, Signer, SignerClient } from '../src/auth';
5+
import { Client, ClientOption } from '../src/client';
96
import { withHttpClient, withInterceptor, withLogger } from '../src/client';
10-
import { ABI } from '../src/common';
11-
import { Address } from '../src/common';
12-
import { Event } from '../src/common';
13-
import { Hash } from '../src/common';
14-
import { Receipt } from '../src/common';
7+
import { ABI, Address, Event, Hash, HttpClient, Receipt, Transaction } from '../src/common';
158
import type { SignedTransaction } from '../src/common';
16-
import { Transaction } from '../src/common';
179
import {
1810
abiFromJSON as ABIFromJSON,
1911
addressFromHex as AddressFromHex,
@@ -22,6 +14,7 @@ import {
2214
zeroAddress,
2315
} from '../src/common';
2416
import { Contract } from '../src/contracts';
17+
import type { BigNumberish, BytesLike } from '../src/providers/eth';
2518
import type { Interceptor, Logf } from '../src/transport';
2619

2720
// Re-export classes
@@ -40,7 +33,16 @@ export {
4033
};
4134

4235
// Re-export types
43-
export type { Interceptor, Logf, Signer, SignerClient, SignedTransaction };
36+
export type {
37+
BigNumberish,
38+
BytesLike,
39+
HttpClient,
40+
Interceptor,
41+
Logf,
42+
Signer,
43+
SignerClient,
44+
SignedTransaction,
45+
};
4446

4547
// Re-export functions
4648
export {

0 commit comments

Comments
 (0)