在 localhost 上将程序部署到 solana 的问题
Posted
技术标签:
【中文标题】在 localhost 上将程序部署到 solana 的问题【英文标题】:Problem with deploying program to solana on localhost 【发布时间】:2021-10-05 08:58:40 【问题描述】:我正在尝试将一些程序部署到我的本地 solana 并且我卡在了这个
-vote-tutorial
> babel-node src/client/deploy_simplest.js
Deploying...
(node:11063) Warning: N-API is an experimental feature and could change at any time.
Our account: Bfoj2PiwU4qvgHbdiQ7AysM4jKVQD73NF9GdwqMs7yzw
Connection to cluster established: http://localhost:8899 'feature-set': 2068214666, 'solana-core': '1.3.15'
-----
Estimated cost to program load: 407338560 lamports ( 0.40733856 ) Sol
ProgramAccount: Axx1mNZpXBSuHqRYv6Bt6r5H5aKMALH8SuWEs9VNJawJ
Error: failed to get recent blockhash: Error: failed to get recent blockhash: Invalid params: unknown variant `finalized`, expected one of `max`, `recent`, `root`, `single`, `singleGossip`.
at Connection.getRecentBlockhash (/home/radoslaw/applications/blockchain/simple-vote-tutorial/node_modules/@solana/web3.js/src/connection.js:2363:13)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
我将学习本教程 https://smith-mcf.medium.com/a-simple-solana-dapp-tutorial-6dedbdf65444
当我使用. start_docker
时
. start_docker
Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
> simplevotetutorial@0.0.1 localnet:up /home/radoslaw/applications/blockchain/simple-vote-tutorial
> set -x; solana-localnet down; set -e; solana-localnet up
+ solana-localnet down
Docker version 20.10.7, build f0df350
++ docker ps --filter 'name=^/solana-localnet$' -q
+ [[ -n '' ]]
+ set -e
+ solana-localnet up
Docker version 20.10.7, build f0df350
+ RUST_LOG=solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=info,solana_bpf_loader=debug,solana_bpf_loader_program=info,solana_rbpf=trace
+ ARGS=(--detach --name solana-localnet --rm --publish 8001:8001/tcp --publish 8899:8899/tcp --publish 8900:8900/tcp --publish 8901:8901/tcp --publish 8902:8902/tcp --publish 9900:9900/tcp --publish 8000:8000/udp --publish 8001:8001/udp --publish 8002:8002/udp --publish 8003:8003/udp --publish 8004:8004/udp --publish 8005:8005/udp --publish 8006:8006/udp --publish 8007:8007/udp --publish 8008:8008/udp --tty --ulimit "nofile=700000" --env "RUST_LOG=$RUST_LOG")
+ [[ -n '' ]]
+ docker run --detach --name solana-localnet --rm --publish 8001:8001/tcp --publish 8899:8899/tcp --publish 8900:8900/tcp --publish 8901:8901/tcp --publish 8902:8902/tcp --publish 9900:9900/tcp --publish 8000:8000/udp --publish 8001:8001/udp --publish 8002:8002/udp --publish 8003:8003/udp --publish 8004:8004/udp --publish 8005:8005/udp --publish 8006:8006/udp --publish 8007:8007/udp --publish 8008:8008/udp --tty --ulimit nofile=700000 --env RUST_LOG=solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=info,solana_bpf_loader=debug,solana_bpf_loader_program=info,solana_rbpf=trace solanalabs/solana:v1.3.15
b3e960613b640aedba3b35d18be03a4e327bab9296bd4e1dba59c0802bd1aecf
+ for _ in 1 2 3 4 5
+ curl -X POST -H 'Content-Type: application/json' -d '"jsonrpc":"2.0","id":1, "method":"getTransactionCount"' http://localhost:8899
curl: (52) Empty reply from server
+ sleep 1
+ for _ in 1 2 3 4 5
+ curl -X POST -H 'Content-Type: application/json' -d '"jsonrpc":"2.0","id":1, "method":"getTransactionCount"' http://localhost:8899
"jsonrpc":"2.0","result":0,"id":1
+ break
当我在 chrome 中运行 localhost:8899
时,响应“不允许使用使用的 HTTP 方法。需要 POST 或 OPTIONS”
我需要说我对 docker 完全是新手,但教程需要它。
【问题讨论】:
【参考方案1】:不幸的是,您似乎在使用新旧混合使用。您看到的错误:
Error: failed to get recent blockhash: Invalid params: unknown variant `finalized`, expected one of `max`, `recent`, `root`, `single`, `singleGossip`.
是因为您使用的是较新版本的 @solana/web3.js 和非常旧的网络版本。最简单的解决方案是降级到 @solana/web3.js 版本 0.78.2 以继续遵循教程。
另外,还有很多用于本地开发的新工具。如果您使用的是新版本的网络和 SDK,则有一个名为 solana-test-validator
(https://docs.solana.com/developing/test-validator) 的二进制文件,它比针对 Docker 开发要容易得多。
【讨论】:
以上是关于在 localhost 上将程序部署到 solana 的问题的主要内容,如果未能解决你的问题,请参考以下文章
在 Amazon Linux 2 上将 node.js 应用程序部署到 Elastic Beanstalk 时出错
在kubernetes上将host作为localhost暴露给节点js app