Use the Node.js SDK to interact with Smart Contract Platform APIs, which allow you interact with smart contracts on the blockchain using the Developer Services platform.
This page provides short examples of how to install and use the Smart Contract Platform SDK. For complete examples, see the Sample Projects page. For more information see the Smart Contract Platform documentation.
To successfully use the Smart Contract Platform SDK, you need the following:
Use the following commands to install the SDK. You can view the package information on the npm site.
npm install @circle-fin/smart-contract-platform --save
To start using the SDK, you first need to configure a client. Import the
initiateSmartContractPlatformClient
factory from the SDK, and then initialize
the client using your API key and entity secret.
The following example shows how to import the client and configure it to use your API key and entity secret:
const {
initiateSmartContractPlatformClient,
} = require('@circle-fin/smart-contract-platform')
const client = initiateSmartContractPlatformClient({
apiKey: '<your-api-key>',
entitySecret: '<your-entity-secret>',
})
The following example shows how to deploy a smart contract using the client:
const response = await client.deployContract({
name: 'First Contract',
description: 'My first hello world contract',
walletId: '004735f6-d9fc-44f8-933c-672cdf3d240d',
abiJson:
"[\n\t{\n\t\t'inputs': [],\n\t\t'stateMutability': 'nonpayable',\n\t\t'type': 'constructor'\n\t},\n\t...",
bytecode: '0x60806040523480156200001157600080fd5b50604051806040...',
constructorParameters: ['TICK', 10000],
feeLevel: 'MEDIUM',
})
console.log(response.data)
The client for the Smart Contract Platform SDK accepts the following configuration parameters:
Option | Required? | Description |
---|---|---|
apiKey | Yes | The API key used to authenticate requests to the Circle API. |
entitySecret | Yes | Your configured entity secret. |
storage | No | Optional custom storage solution for persisting data. If not provided, the SDK uses in-memory storage. |